如何从我的resx文件中检索图像?

fis*_*ead 4 c#

我已经在我的表单的资源文件myForm.resx中添加了一个图像,我想在我的代码文件myForm.cs中使用它,但我并不完全清楚如何获取它的句柄.

Hen*_*man 17

您可以使用Visual Studio添加它(项目,属性,资源,添加现有文件),然后按名称访问它:

   Bitmap bmp = Properties.Resources.<name_you_gave_it>;
Run Code Online (Sandbox Code Playgroud)


psy*_*tik 5

请参阅MSDN for ResourceManager

rm = new ResourceManager("Images", this.GetType().Assembly); 
pictureBox1.Image = (System.Drawing.Image)rm.GetObject("flag");
Run Code Online (Sandbox Code Playgroud)