469,943 Members | 2,688 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Check for icon in ImageList

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!
Nov 20 '05 #1
11 3641
* "Juan Romero" <ju*********@bowne.com> scripsit:
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
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
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.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eR**************@TK2MSFTNGP10.phx.gbl...
* "Juan Romero" <ju*********@bowne.com> scripsit:
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
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #3
"Juan Romero" <ju*********@bowne.com> schrieb
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.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
* "Juan Romero" <ju*********@bowne.com> scripsit:
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?!

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
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!

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eQ**************@TK2MSFTNGP10.phx.gbl...
* "Juan Romero" <ju*********@bowne.com> scripsit:
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?!

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #6
"Juan Romero" <ju*********@bowne.com> schrieb
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.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #7
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!

"Armin Zingler" <az*******@freenet.de> wrote in message
news:Ol**************@TK2MSFTNGP10.phx.gbl...
"Juan Romero" <ju*********@bowne.com> schrieb
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.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #8
* "Juan Romero" <ju*********@bowne.com> scripsit:
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.


<http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindowsFormsImageListImageCollectionCla ssAddTopic1.asp>

<msdn>
Remarks

The Icon is converted to a Bitmap before it is added to the list.
</msdn>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #9
"Juan Romero" <ju*********@bowne.com> schrieb
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

Nov 20 '05 #10
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!
"Armin Zingler" <az*******@freenet.de> wrote in message
news:Oa**************@TK2MSFTNGP09.phx.gbl...
"Juan Romero" <ju*********@bowne.com> schrieb
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

Nov 20 '05 #11
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

"Juan Romero" <ju*********@bowne.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
| 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!
|
|
| "Armin Zingler" <az*******@freenet.de> wrote in message
| news:Oa**************@TK2MSFTNGP09.phx.gbl...
| > "Juan Romero" <ju*********@bowne.com> schrieb
| > > 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
| >
|
|
Nov 20 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by scoobydoo | last post: by
6 posts views Thread by Udi | last post: by
4 posts views Thread by techspirit | last post: by
1 post views Thread by =?Utf-8?B?QWRhbQ==?= | last post: by
7 posts views Thread by =?Utf-8?B?QmVu?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.