开发者

How do I retrieve an image from my resx file?

开发者 https://www.devze.com 2022-12-22 22:10 出处:网络
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 i

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

精彩评论

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