Click here to Skip to main content
15,887,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to read image name from imagelist control during runtime
Kindly help me...
Posted
Updated 17-May-19 6:35am

The Images property of ImageList is of type ImageCollection and is used to add the images to the ImageList as given here.
http://msdn.microsoft.com/en-us/library/system.windows.forms.imagelist.images(v=vs.90).aspx[^]
So, as such the name of the image cannot be obtained from this collection.
The System.Drawing.Image class, which is used within the ImageList, does not have a Name property as can be seen here
http://msdn.microsoft.com/en-us/library/system.drawing.image_properties.aspx[^]
Hence, one option is to set the Tag property of Image, then read the Tag property of the required Image after retrieving it from the ImageList
 
Share this answer
 
C#
for (int i = 0; i < imageList1.Images.Count; i++)
           {
               listBox1.Items.Add( imageList1.Images.Keys[i].ToString());
           }
 
Share this answer
 
Hi Livingstan,


Images in an imagelist don't have names they only have an index.
 
Share this answer
 
Hi can access to a specific image with a name:
VB
Dim _nameimg as string = "ASC"
Dim _idx As Integer = ImageList1.Images.IndexOfKey(_nameimg)
'assing a image to Button
Me.Btn_Sort.Image = ImageList1.Images(_idx)


Antoni
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900