Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

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

Edited by divil
Posted
I don't think you can have a key but you could create an enumeration to make your coding nicer.

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

Posted

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?

Howzit??
  • *Experts*
Posted

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).

Posted

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!!

Posted
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)
Howzit??
Posted

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 :)

Howzit??
  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...