Programmatically change the program icon

2019-07-28 04:47发布

问题:

I'm developing on VS 2010/ C#.

Does any one know how to change the software icon programmatically?

I actually want my software to have one icon under Windows 7 and another for Windows XP in the same software installation.

回答1:

If it's a winform app, you can write below code in the formload event of the main form.

Use this link to find operating system : http://andrewensley.com/2009/06/c-detect-windows-os-part-1/

and then write below code to set icon.

private void InvestorReportingFormLoad(object sender, EventArgs e)
        {
            this.Icon = Properties.Resources.coins;            
        }


回答2:

 this.Icon = Icon.ExtractAssociatedIcon(@"Stringpath");