Hi Everyone-
I am working my way through C# and the Infragistics Controls, kind of still a noob at C#. I am wondering the proper way to use images in the application. For instance, I have a bunch of .ICO icon files. Each of those files contains multiple resolutions. 16x16 and 32x32 being the ones I'm really caring about. There are two places in my app where I want to use these icon images. One place is the listview, at 16x16, another place is on the picturebox, 32x32.
I am just looking for the "proper" way of doing this. Playing around all day, I finally ended up creating two imagelists. One imagelist with the size set to 16x16, another with the size set to 32x32. I named one of them ImageList32x32 and another ImageList16x16. For the listview, I do something like listview....Appearence.Image = ImageList16x16.Images[4] ... For the picturebox I do picturebox...Image = ImageList32x32.Images[4]. That seems to work well, but I'm thinking that the application is possibly compiling two of each .ICO file into the app in order to make it work, and I just do not know if it is the right way of doing it.
Is there another way, possibly to use one imageList and somehow set the Size on the fly? (I've tried this, and when I set the size by doing ImageList.Size = new Size(32,32) it erases the entire imagelist so no images are in it anymore.
Thanks in advance!
The Icon class exposes a constructor overload that takes a stream and a size...as of CLR1.1 there was no way to extract an icon of a given size, that is, if the .ICO had a 16x16 and a 32x32, there was no way to extract the 32x32. I suspect this hasn't changed because icons are sort of a relic from the COM days.
The 'Infragistics File Explorer' sample, which is included with the SDK, demonstrates how to extract the different sizes using the ExtractIconEx API function. This requires unmanaged code permissions as you have to call operating system functions directly.
Awesome! So basically just use .png and have a couple of different sized imageLists! That's what I was thinking but I just wanted to make sure I wasn't missing anything. I hate having [this one person in particular] come in after the fact and sit there for hours telling me how I could have done it differently and better, lol
Thank you very much!
The only thing I want to mention about the ImageList component is that it is a nasty little COM-age critter that makes clones of the images it returns from its indexer. When you assign an image like so:
this.listView.Items[n].Appearance.Image = this.imageList.Images[n];
the ImageList returns a clone of the image from the indexer, so even if you assign what you think is the same image to a hundred different items, the ImageList component will have actually created one hindred different Image instances, each of which are a disposable GDI+ resource. In the case where you have lots of images, this can cause you to max out your GDI+ resources, resulting in things like images disappearing randomly or fonts spontaneously changing. You are better off using a Dictionary that takes some kind of cookie as a key and the image as a value, so that when you access the image via the dictionary's indexer, you get the same instance every time.