473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Tough ImageList Question

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(fil einfo.hIcon))
tn.ImageIndex = tvFolders.ImageList.Images.Count - 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.Images.IndexOf(myImage)
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 2173
Hi,

Since the imagelist.images.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.contains method to
see if you already added the icon. Quick example.
Private Declare Function ExtractIconEx Lib "shell32.dll" 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim arIcons As New ArrayList

Dim strPath As String

ImageList1.Images.Clear()

ImageList1.ImageSize = New Size(32, 32)

strPath = "C:\Windows\Explorer.exe"

arIcons = GetIcon(strPath)

Me.Text = strPath & " icons"

Dim clsIcon As clsIconsFromFile

Dim y As Integer = 0

For Each clsIcon In arIcons

ImageList1.Images.Add(clsIcon.Large)

hticons.Add(clsIcon.Large, y)

y += 1

Dim fs As New System.IO.FileStream(y.ToString & ".ico", IO.FileMode.Create)

clsIcon.Large.Save(fs)

fs.Close()

Next

Dim ico As Icon

ico = DirectCast(arIcons.Item(0), clsIconsFromFile).Large

Debug.WriteLine(hticons.ContainsKey(ico))

ListView1.Items.Clear()

Dim x As Integer

For x = 0 To ImageList1.Images.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 clsIconsFromFile

Dim arIcons As ArrayList

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

ReDim Large(i - 1)

ReDim Small(i - 1)

i = ExtractIconEx(Path, 0, Large, Small, i)

arIcons = New ArrayList

For x = 0 To i - 1

cIcon = New clsIconsFromFile

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

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

arIcons.Add(cIcon)

Next x

Return arIcons

End Function

' Here is the helper class

Public Class clsIconsFromFile

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****************@TK2MSFTNGP11.phx.gbl...
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(fil einfo.hIcon))
tn.ImageIndex = tvFolders.ImageList.Images.Count - 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.Images.IndexOf(myImage)
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***@bellsouth.net> wrote in message
news:ux*************@TK2MSFTNGP10.phx.gbl...
Hi,

Since the imagelist.images.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.contains 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**************@TK2MSFTNGP12.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
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...
2
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....
2
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...
11
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? ...
4
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...
2
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
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:...
6
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 ? ...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.