I have a folder in my project called Resources. It contains a ico image (myIcon.ico). How to I call to this resource to load image to my main forms icon?
Make sure the ico's Build Action property is set to "Embedded Resource" (Click on the file in the solution explorer and it will be available in the properties window)
Then you need to reference your icon using a string. Each folder in your path must be separated with a dot (.)
MyProject
Images
myicon.ico (Embedded Resource)
The string to this resource becomes
"MyProject.Images.myicon.ico"
If your folder starts with a number then you have to include an underscore.
MyProject
32Pixel
myicon.ico
The string to this resource becomes
"MyProject._32Pixel.myicon.ico"
Once you have that string you are set.
Code:
string str = "MyProject.Images.ico.ico";
Stream s = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(str);
Icon ico = new Icon(s);
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.