473,549 Members | 3,109 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tough ImageList Question

If I add an image to an imagelist using
imageList.Image s.Add...
And use it with a tree node
tn.ImageIndex = imageList.Image s.Count-1

This is the actual code:
Win32.Shell.SHG etFileInfo(Node Path, 256, fileinfo, cbFileInfo, flags)
tvFolders.Image List.Images.Add (Icon.FromHandl e(fileinfo.hIco n))
tn.ImageIndex = tvFolders.Image List.Images.Cou nt - 1

It may be that the image is already in the imagelist.
I'd like to check.
The following was suggested to get the index:
Index = imageList.Image s.IndexOf(myIma ge)
But I find IndexOf is not supported.

The only thing I can think of is to save hIcon in an two column array along
with Count=1 and check before I add to the imagelist. But if the imagelist
can tell me if it's already in it I'd rather not have an extra data
structure around.

1)Anyone know how to check the ImageList??

2)If I must have the data structure is an array (hIcon,index) the best one?

Nov 20 '05 #1
4 2185
Hi,

Since the imagelist.image s.contains is not support the best
suggestion I have is to create a hashtable. Store the index of icon in the
hashtable with the icon as the key. Use the hashtable.conta ins method to
see if you already added the icon. Quick example.
Private Declare Function ExtractIconEx Lib "shell32.dl l" Alias
"ExtractIconExA " _

(ByVal lpszFile As String, ByVal nIconIndex As Integer, _

ByVal phiconLarge() As IntPtr, ByVal phiconSmall() As IntPtr, _

ByVal nIcons As Integer) As Integer

Dim hticons As New Hashtable

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

Dim arIcons As New ArrayList

Dim strPath As String

ImageList1.Imag es.Clear()

ImageList1.Imag eSize = New Size(32, 32)

strPath = "C:\Windows\Exp lorer.exe"

arIcons = GetIcon(strPath )

Me.Text = strPath & " icons"

Dim clsIcon As clsIconsFromFil e

Dim y As Integer = 0

For Each clsIcon In arIcons

ImageList1.Imag es.Add(clsIcon. Large)

hticons.Add(cls Icon.Large, y)

y += 1

Dim fs As New System.IO.FileS tream(y.ToStrin g & ".ico", IO.FileMode.Cre ate)

clsIcon.Large.S ave(fs)

fs.Close()

Next

Dim ico As Icon

ico = DirectCast(arIc ons.Item(0), clsIconsFromFil e).Large

Debug.WriteLine (hticons.Contai nsKey(ico))

ListView1.Items .Clear()

Dim x As Integer

For x = 0 To ImageList1.Imag es.Count - 1

Dim lvi As New ListViewItem

lvi.ImageIndex = x

ListView1.Items .Add(lvi)

Next

End Sub

Private Function GetIcon(ByVal Path As String) As ArrayList

Dim Large() As IntPtr

Dim Small() As IntPtr

Dim i, x As Integer

Dim cIcon As clsIconsFromFil e

Dim arIcons As ArrayList

i = ExtractIconEx(P ath, -1, Large, Small, -1) ' get number of icons

ReDim Large(i - 1)

ReDim Small(i - 1)

i = ExtractIconEx(P ath, 0, Large, Small, i)

arIcons = New ArrayList

For x = 0 To i - 1

cIcon = New clsIconsFromFil e

cIcon.Large = Icon.FromHandle (Large(x))

cIcon.Small = Icon.FromHandle (Small(x))

arIcons.Add(cIc on)

Next x

Return arIcons

End Function

' Here is the helper class

Public Class clsIconsFromFil e

Private m_icLarge As Icon

Private m_icSmall As Icon

Public Property Large() As Icon

Get

Return m_icLarge

End Get

Set(ByVal Value As Icon)

m_icLarge = Value

End Set

End Property

Public Property Small() As Icon

Get

Return m_icSmall

End Get

Set(ByVal Value As Icon)

m_icSmall = Value

End Set

End Property

End Class

Ken
--------------------------
" Just Me" <ne********@a-znet.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
If I add an image to an imagelist using
imageList.Image s.Add...
And use it with a tree node
tn.ImageIndex = imageList.Image s.Count-1

This is the actual code:
Win32.Shell.SHG etFileInfo(Node Path, 256, fileinfo, cbFileInfo, flags)
tvFolders.Image List.Images.Add (Icon.FromHandl e(fileinfo.hIco n))
tn.ImageIndex = tvFolders.Image List.Images.Cou nt - 1

It may be that the image is already in the imagelist.
I'd like to check.
The following was suggested to get the index:
Index = imageList.Image s.IndexOf(myIma ge)
But I find IndexOf is not supported.

The only thing I can think of is to save hIcon in an two column array
along
with Count=1 and check before I add to the imagelist. But if the imagelist
can tell me if it's already in it I'd rather not have an extra data
structure around.

1)Anyone know how to check the ImageList??

2)If I must have the data structure is an array (hIcon,index) the best
one?

Nov 20 '05 #2

"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote in message
news:ux******** *****@TK2MSFTNG P10.phx.gbl...
Hi,

Since the imagelist.image s.contains is not support the best
suggestion I have is to create a hashtable. Store the index of icon in the hashtable with the icon as the key. Use the hashtable.conta ins method to
see if you already added the icon. Quick example.


If this you did quickly I'd like to see what you can do given more time.

Thanks a lot. It helped.
Nov 20 '05 #3
I replied before but do not see the reply.

Do you see it?

Anyway, thanks for the help.
Nov 20 '05 #4
Hi,

Your welcome.

Ken
----------------------
" Just Me" <ne********@a-znet.com> wrote in message
news:uZ******** ******@TK2MSFTN GP12.phx.gbl...
I replied before but do not see the reply.

Do you see it?

Anyway, thanks for the help.

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1238
by: Invalid | last post by:
After experiment with and reading about the ImageList and related designers, I'm under the impression that: - Design time support for 32bpp icons and pngs is broken in that they aren't properly added to the resx file, thus you can't utilize ImageList, ToolBar, ListView, etc designers if you want to use such images. - The...
2
6663
by: Michael C | last post by:
One more quick question. I am creating a form that uses an ImageList control. I originally wanted to use a PictureBox control to display the images in the ImageList, but it doesn't seem possible. I found a work-around and used a Label to display, but I'm interested to know if the PictureBox can use an ImageList or not? It would seem to...
2
8509
by: Sanjeeva Reddy | last post by:
hai Anti Keskinen, i have used the following code MyListView->LargeImageList->ImageSize = gcnew System::Drawing::Size(100, 100); // Sets large image size to 100, 100 here i am getting error like "gcnew is undeclared error",how to deeclare 'gcnew" and when i am using in runtime to change the size of images in imagelist in listview control...
11
3898
by: Juan Romero | last post by:
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!
4
4315
by: David | last post by:
I have a problem that just cropped up with using an ImageList in my project I am using VB .NET 200 Problem: I have existing Form with 2 Image List controls. ImageList16 (for 16x16 Images) and ImageList24 (for 24x24). I have inserted images in each and it has worked fine for months... The System.Drawing.Bitmap properties for these images are...
2
1246
by: Just Me | last post by:
If I add an image to an imagelist using imageList.Images.Add... And want to use it with a tree node tn.ImageIndex = imageIndex How do I know what to set imageIndex to?
0
270
by: Just Me | last post by:
If I add an image to an imagelist using imageList.Images.Add... And use it with a tree node tn.ImageIndex = imageList.Images.Count-1 This is the actual code: Win32.Shell.SHGetFileInfo(NodePath, 256, fileinfo, cbFileInfo, flags) tvFolders.ImageList.Images.Add(Icon.FromHandle(fileinfo.hIcon)) tn.ImageIndex = tvFolders.ImageList.Images.Count...
6
1611
by: Tiraman :-\) | last post by:
Hi , i would like to have a form/panel or some thing like that which will display the list of images on it and will implement an onclick for each image. what is the best way to do that ? Thanks
2
3547
by: =?Utf-8?B?S2VuTg==?= | last post by:
We're using a System.Windows.Forms.ImageList to store a bunch of Images that I've loaded, and rendering each image in the ImageList during a draw loop. The process was running unusually slow and was causing memory spikes. After several hours we discovered that the ImageList.Images indexer is actually returning a copy of the added Images...
0
7520
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7718
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.