在Windows中哪里可以找到默认的Winforms图标?

我假设这是Windows中的某个共享资源。 而不是为每个应用程序制作副本,有没有办法使用此图标就像所有Winforms应用程序使用它一样?

默认情况下如何为Winforms应用程序指定? 我没有在代码或项目设置中看到任何图标的引用。 只是它使用“默认图标”。

它作为资源存储在System.Windows.Forms.dll程序集中。 你可以用Reflector获得一份副本。 打开程序集,打开Resources节点,一直到“wfc.ico”。 右键单击“另存为”。 不确定为什么你想要使用它,因为它是默认的。

使用Project + Properties,Application选项卡,Icon设置为应用程序设置自定义图标。 每个表单都有自己的Icon属性。

如果安装了Visual Studio 2010,则会有大量图标(可能包括应用程序图标/ s),请查看以下目录:

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

以前的VS版本可能有类似的目录,如果需要,请查看。

编辑:

app的解压缩文件的文件夹中进行搜索时,有两个值得注意的结果:

Application.icoApplicationGeneric.ico +其* .png对应项。

如果你有VS 2010并且这里的任何图标都合适,我相信你不需要复制一个 – 你应该能够在使用Existing Item...添加时间接地包含文件(作为共享/链接文件) Existing Item...对话框; 您可以通过选择“ Add按钮旁边的箭头并选择“ Add As Link选项来执行此操作。

我看不到按需工作只是覆盖这些文件以尝试应用全局更改。

它作为资源存储在System.Windows.Forms.dll程序集中。 您可以通过以下方式获得带有reflection的副本:

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

因此,您可以在代码中看到相同的Icon.Handle。 同样的参考。 Form.DefaultIcon是Form类中的内部延迟加载静态属性。

您还可以覆盖应用程序的默认Winforms图标。 在Program.cs中,我使用:

 FormUtils.SetDefaultIcon(); 

然后,此函数将使用应用程序属性中指定的图标(可执行文件的图标)覆盖默认图标。

您可以使用Save方法:

C#:

 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