469,625 Members | 1,122 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

Referencing Images...

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

--

May 23 '06 #1
2 3667
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 )
....
....


"Tom" <to*@nospam.com> wrote in message
news:ew**************@TK2MSFTNGP03.phx.gbl...
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

--

May 24 '06 #2
On Tue, 23 May 2006 13:54:21 -0700, "Tom" <to*@nospam.com> wrote:
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
May 25 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Mikey_Doc | last post: by
1 post views Thread by WB | last post: by
3 posts views Thread by Torsten Wiebesiek | last post: by
6 posts views Thread by wangers16 | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.