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

Kieron

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

Ive got all of the icons im using in one DLL (makes them easy to update
should i need to), Ive 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 dont 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 its a bit of a long-winded way of doing it.

As for the namespace+filename, thats not really an issue - its getting the correct index...1 isnt 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, thats what Ive 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...

Theres one other way left, (maybe - any comments from gurus will be apreciated):
Create your own imagelist control, inherited from the normal imagelist, and extend on its 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 its possible.....

EDIT: Ok, cant - You can not inherit from a imagelist control, sorry Ive tried :)
 
ImageLists are meant to store lots of icons that will perform the same function - for instance, youd 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, youd have to create a procedure and hardcode the relationships yourself.
 
Back
Top