Как изменить иконку windows forms

В этой статье Вы узнаете, как поменять иконку в форме Windows Forms в Visual Studio. Это очень легко!

При создании проекта форма со стандартной иконкой выглядит так:

Как поменять иконку в форме Windows Forms на C#

Нам хочется внести оригинальность в оформление нашей программы, и стандартная иконка нам не нужна. Но где же поменять её?

Для этого мы заходим в «Свойства». Они практически всегда находятся в правой части Visual Studio и обозначаются небольшой иконкой 2015-02-17 13-19-12 Скриншот экрана:

Как поменять иконку в форме Windows Forms на C#

Если по каким-либо причинам Вы не нашли «Свойства», то просто кликните правой кнопкой мыши на форме и там выберите этот пункт.

Как поменять иконку в форме Windows Forms на C#

С этим разобрались. Теперь ищем строку с названием Icon. Именно она нам и нужна:

Как поменять иконку в форме Windows Forms на C#

Видим справа тот самый значок, что всегда висит у нас в форме.

Нажимаем на кнопку с многоточием — она откроет нам обозреватель файлов. И, казалось бы, осталось выбрать любую картинку и всё готово, но это не так.

Visual Studio примет в этом параметре только те изображения, которые соответствуют формату .ico (специальный формат для иконок). однако в сети существует множество программ и сайтов, которые без труда переведут любое изображение в формат .ico.

Также существует огромное количество паков и просто отдельных изображений этих форматов. Допустим, мы создали или выбрали наше изображение в нужном формате. Теперь нам остаётся лишь загрузить его.

У нас для примера будет вот такое изображение формата .ico:

Как поменять иконку в форме Windows Forms на C#

Мы выбираем его в обозревателе файлов и нажимаем «Открыть».

Как поменять иконку в форме Windows Forms на C#

Значок в свойствах сменился.

Смотрим на нашу форму:

Как поменять иконку в форме Windows Forms на C#

Всё работает!

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?

Peter Mortensen's user avatar

asked Nov 26, 2010 at 10:35

Srivastava's user avatar

4

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

answered Nov 26, 2010 at 10:56

Javed Akram's user avatar

Javed AkramJaved Akram

15.1k27 gold badges82 silver badges118 bronze badges

0

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;

answered Jan 2, 2019 at 18:15

Csomotor's user avatar

CsomotorCsomotor

3713 silver badges5 bronze badges

5

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)

answered Sep 11, 2013 at 8:46

Lorenz Lo Sauer's user avatar

Lorenz Lo SauerLorenz Lo Sauer

23.8k16 gold badges86 silver badges87 bronze badges

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

answered Nov 26, 2010 at 10:41

KristoferA's user avatar

KristoferAKristoferA

12.3k1 gold badge41 silver badges62 bronze badges

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.

Javed Akram's user avatar

Javed Akram

15.1k27 gold badges82 silver badges118 bronze badges

answered Nov 30, 2015 at 23:30

Josh's user avatar

JoshJosh

711 silver badge1 bronze badge

1

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

answered Oct 6, 2017 at 15:02

Dov's user avatar

DovDov

15.6k13 gold badges76 silver badges177 bronze badges

Put the following line in the constructor of your Form:

Icon = Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetExecutingAssembly().Location);

answered Nov 19, 2021 at 16:10

mrexodia's user avatar

mrexodiamrexodia

68813 silver badges20 bronze badges

This is the way to set the same icon to all forms without having to change one by one.
This is what I coded in my applications.

FormUtils.SetDefaultIcon();

Here a full example ready to use.

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        //Here it is.
        FormUtils.SetDefaultIcon();

        Application.Run(new Form());
    }
}

Here is the class FormUtils:

using System.Drawing;
using System.Windows.Forms;

public static class FormUtils
{
    public static void SetDefaultIcon()
    {
        var icon = Icon.ExtractAssociatedIcon(EntryAssemblyInfo.ExecutablePath);
        typeof(Form)
            .GetField("defaultIcon", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)
            .SetValue(null, icon);
    }
}

And here the class EntryAssemblyInfo. This is truncated for this example. It is my custom coded class taken from System.Winforms.Application.

using System.Security;
using System.Security.Permissions;
using System.Reflection;
using System.Diagnostics;

public static class EntryAssemblyInfo
{
    private static string _executablePath;

    public static string ExecutablePath
    {
        get
        {
            if (_executablePath == null)
            {
                PermissionSet permissionSets = new PermissionSet(PermissionState.None);
                permissionSets.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
                permissionSets.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));
                permissionSets.Assert();

                string uriString = null;
                var entryAssembly = Assembly.GetEntryAssembly();

                if (entryAssembly == null)
                    uriString = Process.GetCurrentProcess().MainModule.FileName;
                else
                    uriString = entryAssembly.CodeBase;

                PermissionSet.RevertAssert();

                if (string.IsNullOrWhiteSpace(uriString))
                    throw new Exception("Can not Get EntryAssembly or Process MainModule FileName");
                else
                {
                    var uri = new Uri(uriString);
                    if (uri.IsFile)
                        _executablePath = string.Concat(uri.LocalPath, Uri.UnescapeDataString(uri.Fragment));
                    else
                        _executablePath = uri.ToString();
                }
            }

            return _executablePath;
        }
    }
}

answered Apr 19, 2022 at 16:31

Roberto B's user avatar

Roberto BRoberto B

5525 silver badges13 bronze badges

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.

answered Nov 26, 2010 at 10:48

LEMUEL  ADANE's user avatar

LEMUEL ADANELEMUEL ADANE

8,35216 gold badges59 silver badges72 bronze badges

1

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

answered Aug 14, 2017 at 14:05

s k's user avatar

s ks k

4,4343 gold badges43 silver badges63 bronze badges

Try this, e.g. in the form constructor:

public Form1()
{
  InitializeComponent();

  string imagePath = @"" + AppDomain.CurrentDomain.BaseDirectory + "path-for-icon";
  using (var stream = File.OpenRead(imagePath))
  {
     this.Icon = new Icon(stream);
  }
}

answered Dec 15, 2021 at 17:19

Sahan Siriwardana's user avatar

I follow Csmotor answer to set icon in my project but I need one more step to convert from Icon to ImageSource.

I shared for whom concerned.

this.Icon = ExportXML.Properties.Resources.IDR_MAINFRAME.ToImageSource();

public static class Helper{
        public static ImageSource ToImageSource(this Icon icon)
        {
            ImageSource imageSource = Imaging.CreateBitmapSourceFromHIcon(
                icon.Handle,
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());

            return imageSource;
        }
    }

answered Nov 28, 2022 at 2:53

Hien Nguyen's user avatar

Hien NguyenHien Nguyen

24.6k7 gold badges52 silver badges64 bronze badges

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.

answered Aug 26, 2019 at 13:14

MeirDayan's user avatar

MeirDayanMeirDayan

6205 silver badges21 bronze badges

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

answered Nov 1, 2019 at 4:28

Chandhu Kuttan's user avatar

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

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

Fateme Mirjalili's user avatar

answered Oct 19, 2020 at 12:30

srinivasan's user avatar

Hi, all today in this article we will show you how to change icon in Windows Forms desktop application. A form icon refers to the image that represents the form in the taskbar, as well as the icon that appears in the form’s title bar. So without further delay, let’s get started.

So far, we’ve seen how to work with C# to create console-based applications. However, in a real-world scenario, teams typically use Visual Studio and C# to create either Windows Forms or web-based applications. Windows Forms is a UI framework for building Windows applications for desktops. It provides one of the most productive ways to build desktop applications based on the visual designer in Visual Studio. Features such as drag-and-drop placement of visual controls make it easy to create desktop applications. Before proceeding, we recommend you to update Windows 

How to Change Icons in Windows Forms Desktop Application

How to change the app icon

Step 1: Create a new Windows Forms application or open an existing application.

Step 2: By default, designer view should be open. If not, right-click the form in the solution explorer window and click View designer profile.

Step 3: Designer view acts as a panel that you can use to add and modify user interface elements. It also reflects what your application will look like at run time. The current icon for your application appears in the upper left corner of the form. If you don’t have an icon, Visual Studio will use a default icon.

Step 4: Mark the form by selecting it, and go to File Properties part. This is usually located in the lower right corner of the Visual Studio window.

Step 5: Click on Three points (…) Next to icon area.

Step 6: In the new file explorer pop-up window, select your new icon. Upload an image that uses an icon format such as an .ico file. If you are having trouble finding or creating icons, you can create a custom icon using Rainmeter.

Step 7: In the File Explorer window, click Open to save the file. This will refresh the canvas with the new icon.

How to run the application and display your icon

Step 1: Click the green Play button at the top of the Visual Studio window.

Step 2: Wait for the application to compile. Once done, the application window will launch with the new icon shown in the upper left corner.

Final Words

We hope you like our article about How to Change Icon in Windows Forms. One of the best third-party UI libraries that offer Winforms controls with advanced features is ComponentOne WinForms Edition. Grapecity’s ComponentOne product line offers developers a complete toolkit of UI controls. It offers over 120 advanced WinForms UI controls and components that help developers create intuitive, modern Windows Forms applications in less time. So, if you like our article, please share it with others.

I hope you understand this article, How to Change Icon in Windows Forms.

James Hogan

James Hogan

James Hogan is a notable content writer recognized for his contributions to Bollyinside, where he excels in crafting informative comparison-based articles on topics like laptops, phones, and software. When he’s not writing, James enjoys immersing himself in football matches and exploring the digital realm. His curiosity about the ever-evolving tech landscape drives his continuous quest for knowledge, ensuring his content remains fresh and relevant.

For a professional application, small details matter. Make sure you consistently communicate your brand across your Windows app, including its icon.

Many icons on a page

If you are creating a new desktop application, you may be following your own branding and design. This might include a custom color palette, UI design, or the icon that displays when a user opens your app.

When using Windows Forms to create your app, Visual Studio adds a default icon in the top-left corner of your application’s window. You can change this to an icon of your choice by modifying the form’s properties.

How to Change the Application’s Icon

You can change the default icon by accessing the form’s properties and uploading a new icon image.

  1. Create a new Windows Forms application or open up an existing one.
  2. By default, the designer view should be open. If not, right-click on the Form in the Solution Explorer window and click on View Designer.
    View Designer option in dropdown menu
  3. The designer view acts as a canvas that you can use to add and modify UI elements. It also reflects what your application will look like at runtime. The current icon for your application shows in the top-left corner of the form. If you do not have an icon, Visual Studio will use a default icon.
    Winforms canvas designer view
  4. Highlight the form by selecting it, and navigate to the Properties pane. This is usually located in the lower right-hand corner of the Visual Studio window.
    Properties window for form with icon field
  5. Click on the three dots (…) next to the Icon field.
  6. In the new file explorer window pop-up, select your new icon. Upload a photo that uses an icon format such as an .ico file. If you are having trouble finding or creating icons, you can create a custom icon using Rainmeter.
  7. In the file explorer window, click on open to save the file. This will update the canvas with the new icon.
    Properties for form with icon field changed

How to Run the Application and View Your Icon

You can view what your new icon looks like at runtime by launching the application.

  1. Click on the green play button at the top of the Visual Studio window.
    Grey play button at the top of Visual Studio
  2. Wait for the application to compile. Once completed, the application window will launch showing the new icon in the top-left corner.
    Winforms at runtime showing new icon

Creating Desktop Applications Using Windows Forms

If you are developing an application using Windows Forms, there is a chance you may want to change the icon to match your design.

You can change the icon in Visual Studio by opening the properties window for the form. You can then upload a new icon image to the icon field.

You may also want to add other UI elements or images to your app. If so, you can learn more about how to add graphics to a Windows Form application.

RRS feed

  • Remove From My Forums
  • Question

  • Hi friends,

    I want to change the icon of a window form which wil be on the top of the form..

    i have taken a new icon and replaced the oldone ..new icon was replaced but there is no change in the form icon..

    In the properrties also i changed.

    but i did not get it…………

    Ramesh d

Answers

  • Open the icon in the IDE with File + Open File, use Image + Current Icon Image Types and tell us what you see in the sub-menu.

All replies

  • Open the icon in the IDE with File + Open File, use Image + Current Icon Image Types and tell us what you see in the sub-menu.

  • Do you mean the icon for the form that resides in the caption?  If so, just set it via the this.Icon propertly, which can also be done via the designer.

  • Yes,the icon which resides above the form..

    I changed the icon property ,….but it is not wowking…

    Ramesh d

  • Does it show an icon at all?

  • Yes,it is showing the icon….but that is not the icon wat i replaced …..it is the icon like a  normal exe symbol.

    At the same time my icon is replacing the exe iamge and my icon is coming in the form of a exe..(this is not the problem) but it is not replacng the form icon.

    Ramesh

  • Ya….now i am getting the icon…………the problem is with the icon image..

    Thanks Ramesh 

  • I have the same problem.

    I’m new to windows form and c#.

    Create a new form project, in the form property I set a new icon, but executable form has no icon at all.

    I tried to creat 16×16, 16 colors and 32×32, 16 colors icon, none of them works!

    What I’m doing wrong?

    Thanks.

  • Project + Properties, Application tab, set the icon.

  • The Problem with the icon………………take the icon with the extension of.ico..

    it works for only .ico files..dont take the gif files and save it as .ico……….it wil not work

    Regards Ramesh d

  • Thanks.

    Actually I found that if I use 16×16, 256 color to draw the icon, the icon will be used.

    As I said, I’m a newbie. when I try to use Visual Studio to create an icon, the default one is not that type. I have th change it manually.

  • Как изменить иконку моего компьютера в windows 10
  • Как изменить имя на экране приветствия windows 10
  • Как изменить иконку exe файла на windows 10
  • Как изменить иконки дисков в windows 10
  • Как изменить иконку меню пуск в windows 10