Set same icon for all my Forms

前端 未结 8 1534
一向
一向 2020-12-08 19:31

Is there any way to set the same icon to all my forms without having to change one by one? Something like when you setup GlobalAssemblyInfo for all your project

8条回答
  •  没有蜡笔的小新
    2020-12-08 19:53

    In additional to Marc's recommendation, you may want your forms to automatically inherit the icon of the executing assembly that contains/calls them.
    This can be done by adding the following code to your inherited form:

    public MyCustomForm()
    {
        Icon = GetExecutableIcon();
    }
    
    public Icon GetExecutableIcon()
    {
        IntPtr large;
        IntPtr small;
        ExtractIconEx(Application.ExecutablePath, 0, out large, out small, 1);
        return Icon.FromHandle(small);
    }
    
    [DllImport("Shell32")]
    public static extern int ExtractIconEx(
        string sFile,
        int iIndex,
        out IntPtr piLargeVersion,
        out IntPtr piSmallVersion,
        int amountIcons);
    

提交回复
热议问题