How to get image from my resx file?

I added an image to my form file, myForm.resx, and I would like to use it in my myForm.cs code file, but I don’t quite understand how to get a handle to it.

+4
source share
4 answers

See MSDN for ResourceManager

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

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

  Bitmap bmp = Properties.Resources.<name_you_gave_it>; 
+17
source

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"); 
0
source
 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); 
-1
source

Source: https://habr.com/ru/post/1303604/


All Articles