7.7 Changing a Windows Form Icon

 <  Day Day Up  >  

7.7 Changing a Windows Form Icon

You want to change the icon displayed in the upper-left corner of a Windows Form.


Technique

Select the form whose icon you want to change and click the browse button in the Icon properties value field. Select the icon you want to use. Figure 7.4 shows a Windows Form with a specified icon.

Figure 7.4. You can change the icon associated with a Windows Form by setting the Icon property.

graphics/07fig04.gif

You can also programmatically set a form's icon by creating an Icon instance and passing the path to an icon file in the constructor. Set the Icon property of the form to the icon object you created:

 
 this.Icon = new Icon( "NewIcon.ico" ); 

Comments

Icons, whether on individual windows or an application icon, serve not only to provide a little visual flair but can also provide information. When setting the icon on a form, you have two choices. You can set a form's icon by using the form editor by clicking on the browse button on that form's icon property in the property browser. A standard file browser dialog appears, allowing you to select an icon file ( .ico ). When you do so, the icon is placed into the resource table of your application. When the form appears, the ResourceManager class loads the icon from your application's resource table and sets the icon on the form using that icon resource. An advantage to using this method other than its obvious simplicity is that you don't have to deploy the icon file with your application.

You can also programmatically change the icon during runtime by creating an Icon object and assigning the Icon property of your Windows Form to that object. Using this dynamic process of changing an icon, you are able to, for instance, create an animated icon for a form to give a visual indication about the state of the application or form at that time. One caveat is that you might be required to deploy the icon file or files with your application. However, Chapter 11, "Localization and Resources," demonstrates how to embed resources in your application similar to the automatic way the form editor does when you set the Icon property within the property browser.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net