Where can I find the default Winforms icon in Windows?

I assume this is a shared resource somewhere on Windows. Instead of making a copy for each application, is there a way to use this icon in the same way that all Winforms applications use it?

How is this indicated for Winforms applications by default? I do not see any links to any icons in the code or project settings. Just that it uses the default icon.

+3
source share
4 answers

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

You set a custom icon for your application using Project + Properties, Application tab, icon settings. Each form has its own icon.

+9
source

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

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

There may be a similar directory for previous versions of VS, see if necessary.

EDIT:

app :

Application.ico ApplicationGeneric.ico + *.png.

VS 2010 - , , - ( / ) Existing Item...; , Add Add As Link.

, , - , .

+4

System.Windows.Forms.dll. 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 the same Icon.Handle icon. The same link. Form.DefaultIcon is an internal lazy loaded static property in the form of a class.

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 file.

+3
source

You can simply use the method Save:

WITH#:

string IcoFilename = "C:\\Junk\\Default.ico";
using (System.IO.FileStream fs = new System.IO.FileStream(IcoFilename, System.IO.FileMode.Create))
{
  this.Icon.Save(fs);
}

Visual Basic:

Dim strFilename As String = "C:\Junk\Default.ico"
Using fs As New System.IO.FileStream(strFilename, IO.FileMode.Create)
  Me.Icon.Save(fs)
End Using
0
source

Source: https://habr.com/ru/post/1795888/


All Articles