Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Load form icon from resource.?

Status
Not open for further replies.

tipatek

Programmer
Jul 30, 2005
8
US
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?

Thanks!
 
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);
 
Not working for me...but I will keep trying it. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top