我已经在我的表单的资源文件myForm.resx中添加了一个图像,我想在我的代码文件myForm.cs中使用它,但我并不完全清楚如何获取它。< / p>
答案 0 :(得分:17)
您可以使用Visual Studio添加它(项目,属性,资源,添加现有文件),然后按名称访问它:
Bitmap bmp = Properties.Resources.<name_you_gave_it>;
答案 1 :(得分:5)
rm = new ResourceManager("Images", this.GetType().Assembly);
pictureBox1.Image = (System.Drawing.Image)rm.GetObject("flag");
答案 2 :(得分:0)
以下代码摘自this link
// Creates the ResourceManager.
System.Resources.ResourceManager myManager = new
System.Resources.ResourceManager("ResourceNamespace.myResources",
myAssembly);
// Retrieves String and Image resources.
System.String myString;
System.Drawing.Image myImage;
myString = myManager.GetString("StringResource");
myImage = (System.Drawing.Image)myManager.GetObject("ImageResource");
答案 3 :(得分:-1)
pictureBox1.Image = new Bitmap (global::<<project namespace>>.Properties.Resources.<<Filename>>);
如下所示,我实施的那个:
pboxSignedInStaffIcon.Image = new Bitmap(global::EasyRent.Properties.Resources.worker1);