Can't change icon
-
I am having trouble changing icons. I edit them with the resource editor, but when I display them they haven't changed. For instance, I'll add an icon to my assembly (Add New Item/Icon file). Then I change its Build Action Property to Embedded Resource. Then I edit the default to what I want. I retrieve the icon with: Icon icon = new Icon(this.GetType(), "MyIcon.ico"); Lastly, I assign this icon to the Icon property of a StatusBar panel. The problem is that the icon hasn't changed from the default image. No amount of saving, rebuilding, etc. seems to do anything. Viewing the image in the icon editor shows the changed icon. Viewing the file with a drawing program (e.g Paint) shows the changed icon. I just cannot get it to diaplsy on my form correctly. What am I doing wrong? Dave
-
I am having trouble changing icons. I edit them with the resource editor, but when I display them they haven't changed. For instance, I'll add an icon to my assembly (Add New Item/Icon file). Then I change its Build Action Property to Embedded Resource. Then I edit the default to what I want. I retrieve the icon with: Icon icon = new Icon(this.GetType(), "MyIcon.ico"); Lastly, I assign this icon to the Icon property of a StatusBar panel. The problem is that the icon hasn't changed from the default image. No amount of saving, rebuilding, etc. seems to do anything. Viewing the image in the icon editor shows the changed icon. Viewing the file with a drawing program (e.g Paint) shows the changed icon. I just cannot get it to diaplsy on my form correctly. What am I doing wrong? Dave
Yes, I have had some trouble with that too. An icon may contain several images, typically at different resolutions; typically 16*16 and 32*32 would be present. On Visual Studio 7.1 look at menu Image/Current Icon Image Types. Which image of the icon file gets used depends heavily on circumstances; it may be different for: - the task bar button - the form's icon - Windows Explorer showing small icons - Windows Explorer showing large icons Furthermore, Windows Explorer sometimes caches the icons used in a folder (I am not sure, maybe in Thumbs.db which may be invisible, depends on your settings). So when designing an icon, you should edit all images it contains, and you may want to delete the icon cache file if you can find one. :)
Luc Pattyn
-
I am having trouble changing icons. I edit them with the resource editor, but when I display them they haven't changed. For instance, I'll add an icon to my assembly (Add New Item/Icon file). Then I change its Build Action Property to Embedded Resource. Then I edit the default to what I want. I retrieve the icon with: Icon icon = new Icon(this.GetType(), "MyIcon.ico"); Lastly, I assign this icon to the Icon property of a StatusBar panel. The problem is that the icon hasn't changed from the default image. No amount of saving, rebuilding, etc. seems to do anything. Viewing the image in the icon editor shows the changed icon. Viewing the file with a drawing program (e.g Paint) shows the changed icon. I just cannot get it to diaplsy on my form correctly. What am I doing wrong? Dave
I think your problem is that you are calling "MyIcon.ico" so it's looking for that file in the current directory. If you are embedding the ico as an ebedded resource it won't be there. You'll need to use Reflection to get the embedded Icon.
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.Stream stream = assembly.GetManifestResourceStream("WindowsApplication3.Icon1.ico");
Icon icon = new Icon(stream);
this.Icon = icon; -
I am having trouble changing icons. I edit them with the resource editor, but when I display them they haven't changed. For instance, I'll add an icon to my assembly (Add New Item/Icon file). Then I change its Build Action Property to Embedded Resource. Then I edit the default to what I want. I retrieve the icon with: Icon icon = new Icon(this.GetType(), "MyIcon.ico"); Lastly, I assign this icon to the Icon property of a StatusBar panel. The problem is that the icon hasn't changed from the default image. No amount of saving, rebuilding, etc. seems to do anything. Viewing the image in the icon editor shows the changed icon. Viewing the file with a drawing program (e.g Paint) shows the changed icon. I just cannot get it to diaplsy on my form correctly. What am I doing wrong? Dave
if you hav ur icons on the resource manager, it is easy to pic the icons. VS hav some built in functions for that use the following code.. (not tested)
statusbar.Icon = global::namespace.Properties.Resources.icon;
namespace - give your name space name. icon - name of the image added in the resource manager. hope this helps -
Yes, I have had some trouble with that too. An icon may contain several images, typically at different resolutions; typically 16*16 and 32*32 would be present. On Visual Studio 7.1 look at menu Image/Current Icon Image Types. Which image of the icon file gets used depends heavily on circumstances; it may be different for: - the task bar button - the form's icon - Windows Explorer showing small icons - Windows Explorer showing large icons Furthermore, Windows Explorer sometimes caches the icons used in a folder (I am not sure, maybe in Thumbs.db which may be invisible, depends on your settings). So when designing an icon, you should edit all images it contains, and you may want to delete the icon cache file if you can find one. :)
Luc Pattyn
Thank you, this solved most of my problems. I must say that all this is not very intuitive. Multiple icons in one file? Also, it would be nice if the IDE's Icon Editor displayed all the images in the file or gave you a hint that there may be more than one. Oh well. Another question: You mentioned that the icon plucked from the file depends on circumstances. Is there any way of extracting a specific icon from a file? For instance, I get the icon with: statusBarPanel.Icon = new Icon(this.GetType(), "MyIcon.ico"); This seems to look for the 16x16 icon. What if I had a circumstance where I wanted a specific size (color...) rather than the default? Thanks, Dave
-
Thank you, this solved most of my problems. I must say that all this is not very intuitive. Multiple icons in one file? Also, it would be nice if the IDE's Icon Editor displayed all the images in the file or gave you a hint that there may be more than one. Oh well. Another question: You mentioned that the icon plucked from the file depends on circumstances. Is there any way of extracting a specific icon from a file? For instance, I get the icon with: statusBarPanel.Icon = new Icon(this.GetType(), "MyIcon.ico"); This seems to look for the 16x16 icon. What if I had a circumstance where I wanted a specific size (color...) rather than the default? Thanks, Dave
Well, all those images together form only one icon, so you better make sure they all look alike. I know of no way to pick a specific image from an icon. If you want to pick a specific icon from many, keep them well apart, i.e. in separate files, or in separate resources. BTW there also exists a way to pack multiple icons (each possibly with multiple images) into a single file, I have forgotten all details tho. Maybe its called an icon list ? :)
Luc Pattyn