Referencing Images...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom

    #1

    Referencing Images...

    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

    --

  • Fred Hedges

    #2
    Re: Referencing Images...

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



    Imports System.Collecti ons.Generics



    ....

    Private m_Images As New Dictionary(Of Integer, Image)
    ....
    ....
    Images .Add ( 21, theImage )
    ....
    ....
    myImage = Images ( 21 )
    ....
    ....
    Images .Remove ( 21 )
    ....
    ....




    "Tom" <tom@nospam.com > wrote in message
    news:ewY3RsqfGH A.4276@TK2MSFTN GP03.phx.gbl...[color=blue]
    >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
    >
    > --
    >[/color]


    Comment

    • gene kelley

      #3
      Re: Referencing Images...

      On Tue, 23 May 2006 13:54:21 -0700, "Tom" <tom@nospam.com > wrote:
      [color=blue]
      >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[/color]

      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.Imag es.SetKeyName(i ndex, "SomeKey")

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

      To delete:
      ImageList1.Imag es.RemoveByKey( "SomeKey")

      Gene


      Comment

      Working...