Problem in changing the custom icon for a Windows form using C#.NE

G

Guest

I am trying to change the form icon of a C# windows application.I am using
the Visual Studio .NET 2003 IDE. I have modified the icon using the icon
editor available in Visual Studio .NET IDE. After saving my changes, when I
try to update the Icon property of the main form , the icon image appears
correctly in the Properties window but the icon image in the upper left
corner of the form does not get updated.
However, I don't find this issue in a windows application created using the
Visual Basic.NET 2003 edition. Why is it that there is a mismatch ? Is this a
bug in C#.NET
2003 edition ?

Steps to reproduce the issue:

1. Open the VS.NET 2003 IDE and create a new C# Windows Application.
2. In the Solution Explorer window, right click on the project name and
add a new Icon file.
3. Double click on the icon file added and modify it in the Icon editor.
4.Now change the Icon property of the main form to the icon file created
and modified in steps 2&3.

Actual Results
The Icon image gets updated in the Properties window but the icon image
in the upper left corner of the form does not get updated. Run the
application and you will find that the form icon in the window caption is
still not updated.

Expected Results
The modified Icon image should get updated in the upper left corner of
the form window.

Here are the configuration details of my development environment:

Operating System : Windows XP Professional
Microsoft .NET framework 1.1 Version 1.1.4322
Microsoft Development Environment 2003 Version 7.1.3088
 
S

Stoitcho Goutsev \(100\)

CodeKracker,



There is couple of possible thinks that may happen in your form as far as I
can see:



1. You use localization: in this case you need to add icon for each culture
that your application support. For example if you have set Localizable to
*true* and you Language to French(Canada) when you open the form in the
designer and change the icon it goes for this culture. If you haven't
changed the default culture and you run the application depending on your
system settings you may see the form from the default culture which still
has the default Icon. However the designer updates the icon as soon as you
load new *.ico file in the Icon property; the runtime is what will be
different.



2. (This second case is probably what happens to you) When you create a new
icon resource the VS creates an ICO file that has icons for two sizes -
16x16 and 32x32 (ICO files can contain more than one icon inside). When you
open the icon in the VS editor by default it opens the 32x32 version of the
icon. However the form caption uses the 16x16 icon if it is available and in
your case it is. Unfortunately the property window shows the 32x32 version.
Say you modify what you see on the screen and save it back to the ICO file.
Then when you load the icon in the form's Icon property the property window
shows the 32x32 version (what you have drawn, but the caption of the forms
shows 16x16 version, which is still the default image. When you run the
application you still see the 16x16 version.



In order to modify the 16x16 version in the image editor open the *Image*
menu and choose 16x16 from the *Current Icon Image Types* sub menu.



Note every time you modify the icon file you need to reload the form's Icon
property because the form's uses copy of the icon from the form's resources.
Updating and saving the ICO file doesn't propagate to the copy in the
resource.



3. It might be combination of both.



I also want to remind you that the icon in the form's property is what you
are going to see on the form's caption and the taskbar, but this is not what
windows explorer (or the desktop for that matter) are going to use. Windows
Explorer uses unmanaged icon resource from the assembly. This *unmanaged*
icon can be changed from the Project settings -> General | Application Icon.
 
G

Guest

Hi Stoitcho Goutsev,
Thank you very much for your reply.It answers my
question to some extent.Visual Basic.NET 2003 by default uses a 32x32 pixel
icon for both the taskbar as well as the form caption. I did not encounter
any problem in updating the icon in the form caption for a windows
application created using Visual Basic.NET 2003. I wonder why there is a
mismatch between C#.NET 2003 and VB.NET 2003 while updating the form icon.
Just throw some light on this if you can.

Thanks..
 
S

Stoitcho Goutsev \(100\)

CodeKracker,

It is not VB, Windows uses the more appropriate icon from the pachage. For
example if there is 16x16 it is going to be used for the form caption and
taskbar;32x32 is going to be used when ALT+TAB etc. If there is not
appropriate icon in the ICO file Windows will take the closest one and up-
or down- scale it. What happens I believe is that VB IDE creates only one
32x32 icon in the ICO file when adding new file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top