如何在C#代码隐藏中显示图片框我的代码:publicMainWindow(){InitializeComponent();地图newMap=newMap();newMap.setMapStrategy(newSmallMapStrategy());newMap.createMap();System.Windows.Forms.PictureBoxpictureBox1=newSystem.Windows.Forms.PictureBox();pictureBox1.Paint+=newSystem.Windows.Forms.PaintEventHandler(newMap.grid[3].afficher);这是一个函数:publicoverridevoidafficher(objectsender,PaintEventArgse){e.Graphics.DrawImage(squareImage,pos_x,pos_y,50,50);}squareImage是Drawing.Image对应的属性。pos_x和pos_y是自定义的int32属性。我想要的是在运行我的应用程序时看到图像...由于您使用的PictureBox是Winforms控件,因此您需要将WindowsFormsHost控件添加到Wpf窗体并将PictureBox添加到其中。每当你动态创建一个控件时,你需要将它添加到一个Form或Container对象中,否则它不会显示出来。即像这样的东西。MainWindow.xamlMainWindow.xaml.cs以上是C#学习教程:C#后台代码如何显示PictureBox共享的所有内容。如果对大家有用,需要进一步了解C#学习教程,希望大家多多关注—namespaceWpfApplication1{//////MainWindow.xaml的交互逻辑///publicpartialclassMainWindow:Window{publicMainWindow(){初始化组件();System.Windows.Forms.PictureBoxpicturebox1=新的System.Windows.Forms。图片框();windowsFormsHost1.Child=picturebox1;picturebox1.Paint+=newSystem.Windows.Forms.PaintEventHandler(picturebox1_Paint);}voidpicturebox1_Paint(objectsender,System.Windows.Forms.PaintEventArgse){System.Drawing.Bitmapbmp=newSystem.Drawing.Bitmap(@"C:Temptest.jpg");System.Drawing.PointulPoint=newSystem.Drawing.Point(0,0);e.Graphics.DrawImage(bmp,ulPoint);}}}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
