473,396 Members | 2,020 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,396 software developers and data experts.

possible to get the exact handle of Icon which is inserted into ImageList

In C#, Is it possible to get the exact handle of Icon which is inserted into ImageList from ImageList?

Note: ImageList_GetIcon() returns not exact handle

Eg.
------------------------------------
Icon x=new Icon(....);
_imageList.Images.Add(x);
IntPtr iHnd=x.Handle;
------------------------------------

And I want from _imageList so that ......
_imageList.something.Handle = x.Handle is satisfied
Nov 19 '08 #1
2 1487
nukefusion
221 Expert 100+
I wouldn't have thought it was possible to do exactly what you want, in the way you want. Here's why:

When you add an Icon to the ImageList, it is first converted to a bitmap, which is a whole new object with a whole new handle. Because of this, the handle of the Icon you added to the ImageList initally will never equal the handle of the corresponding image in the ImageList. They are different objects.
If you want to be able to marry up the original icon with an item in the list at a later date I would suggest using the overload of ImageList.Add that allows you to add a key. You could even use the original handle as a key. See this following example.

Expand|Select|Wrap|Line Numbers
  1.    Icon icon = new Icon(); // Construct your icon here
  2.             IntPtr p1 = icon.Handle;
  3.             string key = p1.ToString();
  4.             imageList1.Images.Add(key, icon);
  5.  
You can then find this image later using:

Expand|Select|Wrap|Line Numbers
  1.   IntPtr p1 = icon.Handle;
  2.             string key = p1.ToString();
  3.             Image i = imageList1.Images[key];
Nov 19 '08 #2
Hey nukefusion,
Its working thnx.
Nov 23 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Terry | last post by:
There are a number of things about using unmanaged resources in Windows Forms programming that is unclear to me. In C++, if you loaded an icon resource using "ExtractIcon()", the resource was...
3
by: scoobydoo | last post by:
hi, I have a problem displaying icons at the right colour depthin a ListView. I've made an icon file, (using IconWorkshop 5), it has 3 icons within it. A 32x32 32bpp XP style icon, a 32x32...
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? ...
3
by: Tony Lugg | last post by:
I have an application with a document management form. When users add documents to the form, I call the API function SHGetFileInfo to get the associated large and small icons for the file. These...
1
by: Thief_ | last post by:
In VB6, I can use: StatusBar1.Panels(1).Picture = ImageList1.ListImages(1).Picture I can't figger out how to do it in VB.Net 2003. I tried converting the project to .Net and got: ...
6
by: Udi | last post by:
Hi, I have an imagelist initialized in design time with several icons files (.ico). However, when I need to extract an icon (Image) from the Imagelist, I can't convert it back to an icon: ...
1
by: Steph. | last post by:
Hi, I load Icons in an ImageList.To do that I have to convert the Icons in the Bitmap format. But HOW can I get My Icon back in a Usable Icon format ?
2
by: giddy | last post by:
hi, I have a listview on a form, the View is set to Tile. I also have an image list tied to the *smallImageList property, i have one image in the image list, its a png : 32X32 When i do...
1
by: =?Utf-8?B?QWRhbQ==?= | last post by:
I'm having a problem loading an Icon into an ImageList. When I load the icon directly it works fine, like this: Icon sourceIcon = << Get an icon from somewhere... >>;...
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
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...
0
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...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.