Set same icon for all my Forms

前端 未结 8 1531
一向
一向 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 20:15

    I wasn't sure if I wanted to use inheritance here, so I used an extension method:

    public static class MyExtensionMethods
    {
        public static void SetAppIcon(this Form form)
        {
            form.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
        }
    }
    

    Then in any form's constructor:

    this.SetAppIcon();
    

    Note: this will cause a crash if you try to run the application from a network location

提交回复
热议问题