2011-03-02 84 views
2

我認爲這是Windows中的某個共享資源。與其爲每個應用程序製作副本,有沒有像使用Winforms應用程序一樣使用此圖標的方法?哪裏可以在Windows中找到默認的Winforms圖標?

默認情況下,這是如何爲Winforms應用程序指定的?我在代碼或項目設置中看不到任何圖標的引用。只是它使用「默認圖標」。

回答

9

它作爲資源存儲在System.Windows.Forms.dll程序集中。你可以得到Reflector的副本。打開程序集,打開「資源」節點,一直到「wfc.ico」。用鼠標右鍵單擊另存爲。不知道爲什麼你想要使用它,因爲它是默認的。

您使用Project + Properties,Application選項卡,Icon設置爲您的應用程序設置了自定義圖標。每個表單都有自己的Icon屬性。

+0

謝謝,我想用它作爲我的WPF應用程序的默認圖標。 – 2011-03-02 23:30:36

4

如果您有Visual Studio 2010的安裝,然後有一個大集合的圖標(可能包括應用程序圖標/秒),請查看以下目錄:

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

有可能是以前的一個類似的目錄VS版本,請看看是否需要。

編輯:

做了app解壓後的文件夾中搜索有兩個顯着的成果:

Application.icoApplicationGeneric.ico +的* .png格式對應。

如果你有VS 2010和這裏的任何圖標都適合,我相信你不需要複製一個 - 你應該能夠間接地包含文件(作爲共享/鏈接文件),當使用Existing Item...對話框添加;您可以通過選擇Add按鈕旁邊的箭頭並選擇Add As Link選項來執行此操作。

我看不到按需要工作的只是覆蓋這些文件,試圖應用全局更改。

2

它作爲資源存儲在System.Windows.Forms.dll程序集中。你可以得到與反思一個副本便接踵而來:

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

此功能將覆蓋在你的應用程序屬性中指定的圖標,可執行文件的圖標默認圖標。

0

您可以只使用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 
相關問題