retrieving an image index on a label

G

Guest

This should be painfully simple but I have spent two days on it and I can't figure it out. I am NEW to vb.net, so please forgive my ignorance

I have a label that I assign an image to through an imagelist index

Label1.Image() = ImageList1.Images(3

This works fine and as expected. In the MouseEnter event I want to check the index of the imagelist to see what image is being displayed and possibly change it

If Label1.ImageIndex = 0 The
Label1.Image() = ImageList1.Images(3
Els
Label1.Image() = ImageList1.Images(0
End I

but this does not work. I ALWAYS get a 0 when I first enter the label then ALWAYS get a -1 from then on. If anyone can help I would greatly appreciate it

Thanks

To
 
C

Cor

Hi Tom,

Can you try this?
\\\
Label1.Imagelist = ImageList1
Label1.Imageindex = 3
///

I think you do not set the imageindex you set the image.
(I never did it that way)
Label1.Image() = ImageList1.Images(3)


I hope this helps?
Cor
 
H

Herfried K. Wagner [MVP]

Tom,

* "=?Utf-8?B?VG9tIEZvc3Rlcg==?= said:
I have a label that I assign an image to through an imagelist index;

Label1.Image() = ImageList1.Images(3)

Instead of doing that, assign the imagelist to the control's 'ImageList'
property and then set its 'ImageIndex' property to 3. Alternatively you
can loop through the images in the imagelist and compare them to the
label's image by using "If Label1.Image Is ImageList1.Images(i)
Then...'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top