ImageLists .NET Style - someone help...please!!

Kieron

Newcomer
Joined
Nov 19, 2002
Messages
15
Location
England
Hi,

I've got all of the icons i'm using in one DLL (makes them easy to update
should i need to), I've then got three projects (part of the one solution)
using this file to retrieve the icons...this means that all my icon
associations are in code, not in the UI. Is there any way of using a Key
property like the ImageList in VB6 instead of this terrible index only
thang??

Regards
Kieron
 
Last edited by a moderator:
I don't know how you currently retrieve the icons out of the dll, but if you use the 'Assembly.GetManifestResourceStream' method, you must specify a full namespace + filename for the required icon.

Will this be a sufficient key?
 
You could always add the images to an ArrayList that you create
yourself, rather than using an ImageList. Unless you are binding the
ImageList to a control which requires it (such as a toolbar), then I
see no real need for using it like that.

You could also build your own pseudo-ImageList control which
allowed you to add items that did have a Key property (a
class that you make yourself).
 
I thought of an enumeration but it's a bit of a long-winded way of doing it.

As for the namespace+filename, that's not really an issue - it's getting the correct index...1 isn't as meaningful as ID_Customers!!
 
My suggestion will only work if you add all the icons as embedded resource in this dll (instead of the imagelist). You can then get them out by using a key (namespace + filename)
 
Hi, that's what I've done...the image lists are in each form and the appropriate icons loaded from the DLL via the manifest stream.
 
Ok, so you load the icons into the imagelists @ runtime...

There's one other way left, (maybe - any comments from guru's will be apreciated):
Create your own imagelist control, inherited from the normal imagelist, and extend on it's 'Images' collection by adding another Indexer (overload the original one). As I was saying, the suggestion is a quick thought but you will have investigate if it's possible.....

EDIT: Ok, can't - You can not inherit from a imagelist control, sorry I've tried :)
 
ImageLists are meant to store lots of icons that will perform the same function - for instance, you'd fill an imagelist and associate it with a toolbar if you wanted a store of images for that use. Keys were omitted because they are not necessary for this - designers show a dropdown menu of images to choose from.

If you are using an ImageList as a general repository for images in your application, you might consider embedding them all as resources in your app instead. As I said, ImageLists are meant to store a group of similar images, keys would be a waste.

That said, you could always use a dictionary object like a Hashtable to build a relationship of strings to images at runtime, you'd have to create a procedure and hardcode the relationships yourself.
 
Back
Top