Referencing Images...

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

I need to be able to reference some images stored in my VB.NET program.
Normally, I would load the images into an ImageList control and use
them from there (these are going to be icons). However, I need to be
able to add/delete images from this image 'store' (whatever I end up
using); but because an image list only allows referencing by image
number in the list, when I would delete an image/icon it would 'mess'
up the ones following that because obviously the image number would
change. Also, I want to allow the user to load custom images/icons of
their own, which again (especially when deleting images) would allow
things to get screwed up because the image number would be affected
(i.e. in the program I would allows my main database records to 'store'
the key to an image - if that key is simply the image number in the
image list, then it is going to be incorrect if any image before that
gets deleted).

In the old VB 6 ImageList one could assign each image a 'key' - but
that isn't used in the new .NET image list. There has got to be a way
to store some kind of unique key to an image and then use that key
(perhaps a hash list or something). Anyone got a good way to handle
this? THanks in advance.

Chimp

--
 
You can use a Dictionary to do this, assigning some key and storing Images:



Imports System.Collections.Generics



....

Private m_Images As New Dictionary(Of Integer, Image)
....
....
Images .Add ( 21, theImage )
....
....
myImage = Images ( 21 )
....
....
Images .Remove ( 21 )
....
....
 
I need to be able to reference some images stored in my VB.NET program.
Normally, I would load the images into an ImageList control and use
them from there (these are going to be icons). However, I need to be
able to add/delete images from this image 'store' (whatever I end up
using); but because an image list only allows referencing by image
number in the list, when I would delete an image/icon it would 'mess'
up the ones following that because obviously the image number would
change. Also, I want to allow the user to load custom images/icons of
their own, which again (especially when deleting images) would allow
things to get screwed up because the image number would be affected
(i.e. in the program I would allows my main database records to 'store'
the key to an image - if that key is simply the image number in the
image list, then it is going to be incorrect if any image before that
gets deleted).

In the old VB 6 ImageList one could assign each image a 'key' - but
that isn't used in the new .NET image list. There has got to be a way
to store some kind of unique key to an image and then use that key
(perhaps a hash list or something). Anyone got a good way to handle
this? THanks in advance.

Chimp

If you manage to add images in Design to an ImageList componet
(doesn't work, here), you should be able to add keys at runtime:

ImageList1.Images.SetKeyName(index, "SomeKey")

By your description, it may better to simply populate the ImageList at
runtime:
ImageList1.Images.Add("SomeKey", SomeImage)

To delete:
ImageList1.Images.RemoveByKey("SomeKey")

Gene
 
Back
Top