CK Cybers Time

Tuesday, May 1, 2007

Create Icon

Create Icon with Microsoft Visual C# There are a few things I should mention about Icon files. First they can hold multiple sizes and color depths in them. That is one icon file can have 16 X 16 pixels, 32 X 32, 48 x 48, 64 X 64, 96 X 96. Each one of those sizes can have three color options: monochrome, 16 colors and 256 colors. Now if you only have a 16 X 16 image, your application will use that image in the window explore, but you will get some default image for a desktop shortcut. You need a 32 X 32 or higher image for the desktop shortcut. So you need at least two images. One image 16 X 16 pixels in size and the other image is 32 X 32 pixels or larger in size.


Icon files

Creating the Icon file

First you want to add a new Icon file to your windows application project. Make sure you name it properly. In our example I am just taking the default Icon1.ico name.

New file Dialog VS Icon File

Next you will want to open the bitmap file you want to convert to an icon in MS Paint. We are going to strip off any text, get the file into a square that fits one of the above sizes. In this example we are going for 64 x 64 pixels. Then we will copy the images from paint and pasting it into the correct image type in Visual Studio.

Tech-pro bitmap Tech-pro bitmap with text removed and centered

We need to create the correct new image type in the icon file. We are going to create a 64 X 64 pixels 256 color image type. So select the Icon file in Visual Studio and then right click and select New Image type. The new Icon Image Type dialog will come up so we can select the one we want.

New Icon Image type dialog

Next we will need to properly set the background color of the new Icon Image type. It defaults to a blue color. In this example I am picking white, but you should choose whatever color works best for your image. It is easiest to change the color all at once. If you go to the Image menu then tools then fill tool you can then select a color from the palate and set the background color of the icon image type. Next go to paint and do a select all and copy. Next go back to Visual Studio and paste into the icon file.

VS Icon file paste

We will be repeating this process for the other icon images sizes. Next we need to go back to paint to create our 16 X 16 pixel image. If you go to the Image menu and the stretch/skew we can reduce the image by half making it 32 X 32. We will do this again to get the image down to 16 X 16.

MS Paint stretch/skew

Next we need to change the image attributes to have a width of 16 and a height of 16. In MS Paint go to the Image menu then attributes. Back in Visual Studio we need to create a new icon image type of 16 X 16 pixels with 256 colors. Set the background color of the new icon image type. Copy the image from MS Paint and paste it into the new icon image.

At this point we have the two icon image files that are necessary for what we want in an icon file. Go to your windows form and select the icon property. Select the icon we have just created. This will cause the form itself to use the icon. Next go to the project properties and change the icon to be the one you just created. This will cause the icon to be used in windows explore, a short cut on the desktop and the application down on the tray.

Tech-pro desktop icon

Finally you may want to delete the default icon image types. They are both 16 colors. Note you may want to add a 32 X 32 pixel image as well. To switch between icon image types, just right click on the icon file and select current icon image types. That will allow you to select the existing icon image types in the icon file.