Check for icon in ImageList

  • Thread starter Thread starter Juan Romero
  • Start date Start date
J

Juan Romero

Hey guys,

I have an ImageList control that stores my icons. What I need to do is find
out if the icon at hand already exists in the ImageList so I dont enter it
twice. How can I do that?

Thanks in advance!
 
* "Juan Romero said:
I have an ImageList control that stores my icons. What I need to do is find
out if the icon at hand already exists in the ImageList so I dont enter it
twice. How can I do that?

\\\
If ImageList1.Images.Contains(Bitmap1) Then
...
Else
...
End If
///
 
Thanks for answering.

The contains method is not supported in VB.NET.
What I have in the image list is not a bitmap or image, but AN ICON. That is
why it is so difficult.
Any other ideas anyone out there?

Thanks in advance.
 
Juan Romero said:
Thanks for answering.

The contains method is not supported in VB.NET.
What I have in the image list is not a bitmap or image, but AN ICON.
That is why it is so difficult.
Any other ideas anyone out there?


An imagelist contains images, not icons. An icon is not an image. Images are
Bitmaps or Metafiles.
 
* "Juan Romero said:
The contains method is not supported in VB.NET.

Sorry, I read that later in the docs...
What I have in the image list is not a bitmap or image, but AN ICON. That is
why it is so difficult.

An imagelist cannot store icons. How do you add them?!
 
Well, believe it or not, you ARE IN FACT able to add icons to the list.
One of the declarations of the "add" method of the images collection of the
imagelist accepts a system.drawing.icon as a parameter.

Check it out.

Thanks!
 
Juan Romero said:
Well, believe it or not, you ARE IN FACT able to add icons to the
list. One of the declarations of the "add" method of the images
collection of the imagelist accepts a system.drawing.icon as a
parameter.

Check it out.

Yes, but it is converted to a bitmap.
 
Correct, which is exactly my problem, how do I compare the bitmap to the
icon?
Don't forget that what I want to do is to find out if a particular icon has
been entered into the imagelist (even if it was converted to a bitmap).
There is no conversion from bitmap to icon or viceversa, or maybe there is
and I dont know about it?

Thanks!
 
Juan Romero said:
Correct, which is exactly my problem, how do I compare the bitmap to
the icon?
Don't forget that what I want to do is to find out if a particular
icon has been entered into the imagelist (even if it was converted to
a bitmap). There is no conversion from bitmap to icon or viceversa,
or maybe there is and I dont know about it?

I guess I didn't understand the question. To find out if the image has been
inserted in the imagelist, you must have a look at the content of the
imagelist.

Maybe Herfried knows the answer.
 
Yes.....
The problem is that I am inserting ICONS. Icons get converted into bitmaps,
so once the icon is in there, there is no way I can check it.

For instance, suppose I add "iconA" to the imagelist. I don't want to have
the same icon more than once on that imagelist, so the next time I add an
icon, I want to be able to check if the icon exists already in the list. The
problem is that when the icon is inserted into the list, it is converted and
stored as a bitmap, so when I check, I end up comparing AN ICON AGAINST A
BITMAP. So the issue is how do I make this work out. The only possible way I
see is to convert one of them to the opposite format, WHICH IS NOT POSSIBLE,
or at least I dont know how.

If anyone knows how, or an alternative way of dealing with this, please let
me know.

Thanks!
 
Hi Juan,

Does this answer your question:
' Retreive Bitmap from imageList

Dim bmp As Bitmap = DirectCast(Me.imgICO16.Images(1), Bitmap)

' Convert bitmap to Icon

Dim ico As Icon = Icon.FromHandle(bmp.GetHicon)

' Perform your logic

HTH,

Michael

| Yes.....
| The problem is that I am inserting ICONS. Icons get converted into
bitmaps,
| so once the icon is in there, there is no way I can check it.
|
| For instance, suppose I add "iconA" to the imagelist. I don't want to have
| the same icon more than once on that imagelist, so the next time I add an
| icon, I want to be able to check if the icon exists already in the list.
The
| problem is that when the icon is inserted into the list, it is converted
and
| stored as a bitmap, so when I check, I end up comparing AN ICON AGAINST A
| BITMAP. So the issue is how do I make this work out. The only possible way
I
| see is to convert one of them to the opposite format, WHICH IS NOT
POSSIBLE,
| or at least I dont know how.
|
| If anyone knows how, or an alternative way of dealing with this, please
let
| me know.
|
| Thanks!
|
|
| | > > Correct, which is exactly my problem, how do I compare the bitmap to
| > > the icon?
| > > Don't forget that what I want to do is to find out if a particular
| > > icon has been entered into the imagelist (even if it was converted to
| > > a bitmap). There is no conversion from bitmap to icon or viceversa,
| > > or maybe there is and I dont know about it?
| >
| > I guess I didn't understand the question. To find out if the image has
| been
| > inserted in the imagelist, you must have a look at the content of the
| > imagelist.
| >
| > Maybe Herfried knows the answer.
| >
| >
| > --
| > Armin
| >
| > http://www.plig.net/nnq/nquote.html
| > http://www.netmeister.org/news/learn2quote.html
| >
|
|
 
Back
Top