Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any easy way to use icons from resources?

I have an C# app. I need to add an icon to that app so i added an icon resource. Adding resource went fine, but is there any way to use my (resource) icon as form icon WITHOUT adding additional code? When i try to use design-time "icon" property of form it seems i have to choose a file, but i want to use embedded icon...

Any help?

like image 794
guest86 Avatar asked Apr 13 '11 23:04

guest86


People also ask

How do I add an icon to a resource file?

Just right click on your project-> add-> resource. Add resource window would have popped up where in you can select icon as your preference and select import. Then it lets you to browse through your directory and select your icon.

How do I add icons to Visual Studio project?

On the menu bar, choose Project > Properties. When the Project Designer appears, choose the Application tab. (Visual Basic)—In the Icon list, choose an icon (. ico) file.


2 Answers

  1. Add the icon to the project resources and rename to icon.

  2. Open the designer of the form you want to add the icon to.

  3. Append the InitializeComponent function.

  4. Add this line in the top:

    this.Icon = PROJECTNAME.Properties.Resources.icon; 

    repeat step 4 for any forms in your project you want to update

like image 169
Moudi Avatar answered Sep 19 '22 12:09

Moudi


How I load Icons: Using Visual Studio 2010: Go to the project properties, click Add Resource > Existing File, select your Icon.

You'll see that a Resources folder appeared. This was my problem, I had to click the loaded icon (in Resources directory), and set "Copy to Output Directory" to "Copy always". (was set "Do not copy").

Now simply do:

Icon myIcon = new Icon("Resources/myIcon.ico"); 
like image 25
user1481088 Avatar answered Sep 17 '22 12:09

user1481088