VS2010中关于ICON的一点知识

在看world wind时,遇到一个问题。查了好多资料,最后在老外的网站上终于找到了相关资料。保存一下

In .NET framework, the Icon class represents a Windows icon, which is a small bitmap image used to represent an object. The icon class is defined in System.Drawing namespace. So before using Icon class, you need to reference the System.Drawing namespace to your application.

You can set icon of a form at run-time as well as at design-time. You use a form's Icon property to set form's icon at design-time. Which actually adds two lines to your source code:

System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof(Form1));
this.Icon = (System.Drawing.Icon) resources.GetObject ("$this.Icon");

Creating an Icon Object at run-time

You can can create an icon object at run-time and set it as icon of a Form. You use Icon constructor to create an icon object. The Icon constructor is an overloaded method:

In this sample example, I load tst.ico file as an icon of the form.

System.Drawing.Icon ico = new System.Drawing.Icon("c:\\temp\\tst.ico");
this.Icon = ico ;

You can even set icon's size by using other overloaded constructors.

posted @ 2012-04-10 12:15  完美视界  阅读(836)  评论(0编辑  收藏  举报