Where to find the default Winforms icon in Windows?

20,608

Solution 1

It is stored as a resource in the System.Windows.Forms.dll assembly. You could get a copy with Reflector. Open the assembly, open the Resources node, all the way down to "wfc.ico". Right-click, Save As. Not sure why you'd want to use it, given that it is the default.

You set a custom icon for your application with Project + Properties, Application tab, Icon setting. Each form has its own Icon property.

Solution 2

If you have Visual Studio 2010 installed then there is a large collection of icons (potentially including the application icon/s), check out the following directory:

%ProgramFiles%\Microsoft Visual Studio 10.0\Common7\VS2010ImageLibrary\1033

There may be a similar directory for previous VS versions, take a look if needs be.

EDIT:

On doing a search in the folder of the unzipped file for app there are two notable results:

Application.ico and ApplicationGeneric.ico + its *.png counterpart.

If you have VS 2010 and any of the icons in here are suitable, I believe you don't need to copy a single one - you should be able to include the file indirectly (as a shared/linked file) when adding using the Existing Item... dialog; you do this by selecting the arrow next to Add button and selecting the Add As Link option.

What I can't see working as desired is simply overwriting these files in an attempt to apply a global change.

Solution 3

It is stored as a resource in the System.Windows.Forms.dll assembly. You could get a copy with reflection as folow:

public static class FormUtils
{
    private static Icon _defaultFormIcon;
    public static Icon DefaultFormIcon
    {
        get
        {
            if (_defaultFormIcon == null)
                _defaultFormIcon = (Icon)typeof(Form).
                    GetProperty("DefaultIcon", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).GetValue(null, null);

            return _defaultFormIcon;
        }
    }

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

public static class FormExtensions
{
    internal static void GetIconIfDefault(this Form dest, Form source)
    {
        if (dest.Icon == FormUtils.DefaultFormIcon)
            dest.Icon = source.Icon;
    }
}

So as you can see in the code you have in this way the same Icon.Handle. The same reference. Form.DefaultIcon is an internal lazy loaded static property in class Form.

You can also override the default Winforms icon for your application. In Program.cs i use:

FormUtils.SetDefaultIcon();

This function will then override the default icon with the icon specified in your Application properties, the icon of your executable.

Share:
20,608
Joan Venge
Author by

Joan Venge

Professional hitman.

Updated on February 08, 2022

Comments

  • Joan Venge
    Joan Venge over 2 years

    I assume this is a shared resource somewhere in Windows. Rather than making a copy for each app, is there a way to use this icon just like all Winforms apps use it?

    How is this specified for Winforms apps by default? I don't see any reference of any icons in code or project settings. Just that it uses the "default icon".

  • Joan Venge
    Joan Venge about 13 years
    Thanks, I want to use it as the default icon for my WPF apps.