[c#] Changing the default icon in a Windows Forms application

I need to change the icon in the application I am working on. But simply browsing for other icons from the project property tab -> Application -> Icon, it is not getting the icons stored on the desktop..

What is the right way of doing it?

This question is related to c# visual-studio winforms

The answer is


Add your icon as a Resource (Project > yourprojectname Properties > Resources > Pick "Icons from dropdown > Add Resource (or choose Add Existing File from dropdown if you already have the .ico)

Then:

this.Icon = Properties.Resources.youriconname;


The icons you are seeing on desktop is not a icon file. They are either executable files .exe or shortcuts of any application .lnk. So can only set icon which have .ico extension.

Go to Project Menu -> Your_Project_Name Properties -> Application TAB -> Resources -> Icon

browse for your Icon, remember it must have .ico extension

You can make your icon in Visual Studio

Go to Project Menu -> Add New Item -> Icon File


The Simplest solution is here: If you are using Visual Studio, from the Solution Explorer, right click on your project file. Choose Properties. Select Icon and manifest then Browse your .ico file.


Once the icon is in a .ICO format in visual studio I use

//This uses the file u give it to make an icon. 

Icon icon = Icon.ExtractAssociatedIcon(String);//pulls icon from .ico and makes it then icon object.

//Assign icon to the icon property of the form

this.Icon = icon;

so in short

Icon icon = Icon.ExtractAssociatedIcon("FILE/Path");

this.Icon = icon; 

Works everytime.


I found that the easiest way is:

  1. Add an Icon file into your WinForms project.
  2. Change the icon files' build action into Embedded Resource
  3. In the Main Form Load function:

    Icon = LoadIcon("< the file name of that icon file >");


Select your project properties from Project Tab Then Application->Resource->Icon And Manifest->change the default icon

This works in Visual studio 2019 finely Note:Only files with .ico format can be added as icon


You can change the app icon under project properties. Individual form icons under form properties.


I added the .ico file to my project, setting the Build Action to Embedded Resource. I specified the path to that file as the project's icon in the project settings, and then I used the code below in the form's constructor to share it. This way, I don't need to maintain a resources file anywhere with copies of the icon. All I need to do to update it is to replace the file.

var exe = System.Reflection.Assembly.GetExecutingAssembly();
var iconStream = exe.GetManifestResourceStream("Namespace.IconName.ico");
if (iconStream != null) Icon = new Icon(iconStream);

On the solution explorer, right click on the project title and select the 'Properties' on the context menu to open the 'Project Property' form. In the 'Application' tab, on the 'Resources' group box there is a entry field where you can select the icon file you want for your application.


The Icon displayed in the Taskbar and Windowtitle is that of the main Form. By changing its Icon you also set the Icon shown in the Taskbar, when already included in your *.resx:

System.ComponentModel.ComponentResourceManager resources = 
    new System.ComponentModel.ComponentResourceManager(typeof(MyForm));
this.Icon = ((System.Drawing.Icon)(resources.GetObject("statusnormal.Icon")));

or, by directly reading from your Resources:

this.Icon = new Icon("Resources/statusnormal.ico");

If you cannot immediately find the code of the Form, search your whole project (CTRL+SHIFT+F) for the shown Window-Title (presuming that the text is static)


select Main form -> properties -> Windows style -> icon -> browse your ico

this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to visual-studio

VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio? How to download Visual Studio Community Edition 2015 (not 2017) Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio Code pylint: Unable to import 'protorpc' Open the terminal in visual studio? Is Visual Studio Community a 30 day trial? How can I run NUnit tests in Visual Studio 2017? Visual Studio 2017: Display method references

Examples related to winforms

How to set combobox default value? Get the cell value of a GridView row Getting the first and last day of a month, using a given DateTime object Check if a record exists in the database Delete a row in DataGridView Control in VB.NET How to make picturebox transparent? Set default format of datetimepicker as dd-MM-yyyy Changing datagridview cell color based on condition C# Inserting Data from a form into an access Database How to use ConfigurationManager