Any easy way to use icons from resources?

C#FormsResourcesIcons

C# Problem Overview


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?

C# Solutions


Solution 1 - C#

  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

Solution 2 - C#

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");

Solution 3 - C#

choosing that file, will embed the icon in the executable.

Solution 4 - C#

Forms maintain separate resource files (SomeForm.Designer.resx) added via the designer. To use icons embedded in another resource file requires codes. (this.Icone = Project.Resources.SomeIcon;)

Solution 5 - C#

After adding the ICO file to your apps resources, you can use references it using My.Resources.YourIconNameWithoutExtension

For example if I had a file called Logo-square.ico added to my apps resources, I can set it to an icon with:

NotifyIcon1.Icon = My.Resources.Logo_square

Solution 6 - C#

On Form_Load:

this.Icon = YourProjectNameSpace.Resources.YourResourceName.YouAppIconName;

Solution 7 - C#

in visual studio for vb.net, go to the project properties, click Add Resource > Existing File, select your Icon.

in your code: Me.Icon = My.Resources.IconResourceName

Solution 8 - C#

You can use this without extra size also

this.Icon = Icon.ExtractAssociatedIcon(AppDomain.CurrentDomain.FriendlyName);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionguest86View Question on Stackoverflow
Solution 1 - C#MoudiView Answer on Stackoverflow
Solution 2 - C#user1481088View Answer on Stackoverflow
Solution 3 - C#The Lazy CoderView Answer on Stackoverflow
Solution 4 - C#bricklayer137View Answer on Stackoverflow
Solution 5 - C#A.BadgerView Answer on Stackoverflow
Solution 6 - C#Lucas PonzoView Answer on Stackoverflow
Solution 7 - C#RobView Answer on Stackoverflow
Solution 8 - C#Mohamed HamdyView Answer on Stackoverflow