Applications Resources: Icons
Like a bitmap, an icon is used to display graphics on window objects. While a bitmap can have any dimension the window needs, the size of an icon is limited. This is because icons assume different roles on an application.
To create an icon, once again, you can use any application that has the capability. Normally, you can use Visual Studio to create or design an icon. To do this, on the main menu of Visual Studio, you can click Project -> Add New Itemů Then, in the Add New Item dialog box, you can select Icon File, give it a name and click Open.
When you start designing an icon, you would be presented with a drawing area whose actual dimensions are 32 x 32 pixels. This is the size of the icon that displays as Large Icon. Here is an example from the New File dialog box Visual Studio in the Templates list:
In some cases, you may allow the user to display smaller icons, which are 16x16 pixels:
To make this possible, you can associate a second icon to the 32x32 one. The application you use to design your icon should make it simple for you to add this second icon. To do this in Visual Studio, while the icon is displaying, on the main menu, you can click Image -> New Image Type... Select 16x16, 256 colors and click OK.
Whether you create only one or both versions of the icon, it is stored, or both are stored in a single file whose extension is .ico
Particularly in Visual C# more than in Visual C++, when you create or design an icon, your Visual C# application doesn't own the icon. This means that it is up to you to design what you want to do with the icon. As we will learn in various lessons, icons can be used in various scenarios, including representing the system icon on the left section of the title bar of a form.
To support icons, the .NET Framework provides the Icon class. To use an icon in your application, you can first declare an Icon variable using one of the class' constructors. If the icon is stored in a file, the simplest constructor to use it has the following syntax:
public Icon(string filename);
With this constructor, the path to the icon file is passed as argument. After creating the icon, if you want to use only one size version, you can use one the following constructors to declare the variable:
public Icon(Icon original, Size size); public Icon(Icon original, int width, int height);
After initializing an Icon variable, if you want to get its dimensions, you can access its Width property and its Height property, or its Size property.
As mentioned already, there are various ways an icon can be used. For example, you can display it in a control by drawing it. To do this, you can call the Graphics.DrawIcon() method which is overloaded with two versions:
public void DrawIcon(Icon icon, Rectangle targetRect); public void DrawIcon(Icon icon, int x, int y);
The first version allows you to specify the location and dimensions of the icon. The second version allows you to specify only the location of the icon.
|Home||Copyright © 2004-2010 FunctionX, Inc.|