以编程方式更改程序图标

问题描述:

我正在VS 2010/C#上进行开发.

I'm developing on VS 2010/ C#.

有人知道如何以编程方式更改软件图标吗?

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

我实际上希望我的软件在同一软件安装中的Windows 7下具有一个图标,而对于Windows XP则具有另一个图标.

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

如果它是winform应用程序,则可以在主表单的formload事件中编写以下代码.

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

使用此链接找到操作系统: http://andrewensley.com/2009/06/c- detect-windows-os-part-1/

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