开发者

How do I retrieve an image from my resx file?

I have added an image to my form's resource file, myForm.resx, and I would like to use it in my code file, myForm.cs, but I am not entirely clear on h开发者_StackOverflow中文版ow to get a handle to it.


You can just use Visual Studio to add it (Project, Properties, Resources, Add existing file), and then access it by name:

   Bitmap bmp = Properties.Resources.<name_you_gave_it>;


See MSDN for ResourceManager

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


The following code is extracted from 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");


pictureBox1.Image = new Bitmap (global::<<project namespace>>.Properties.Resources.<<Filename>>);

Like the following, the one I implemented:

pboxSignedInStaffIcon.Image = new Bitmap(global::EasyRent.Properties.Resources.worker1);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜