473,692 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extract an icon from an imagelist

Udi
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:

statusBarPanel1 .Icon = imageList1.Imag es[0]; // cast/as don't work
// Cannot convert type 'System.Drawing .Image' to 'System.Drawing .Icon'

What am I mising here?
Thanks!
Udi.

Jan 24 '06 #1
6 10999
Udi,

Unfortunately getting an icon from an image list is a function that is
not exposed in the managed class. However, you can get the icon yourself,
by calling the ImageList_GetIc on function through the P/Invoke layer. You
can pass the handle of the imagelist (exposed by the HandleProperty) to the
function and it will return a handle, which you can then pass to the static
FromHandle property on the Icon class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Udi" <Ud**********@g mail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
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:

statusBarPanel1 .Icon = imageList1.Imag es[0]; // cast/as don't work
// Cannot convert type 'System.Drawing .Image' to 'System.Drawing .Icon'

What am I mising here?
Thanks!
Udi.

Jan 24 '06 #2
>From http://ryanfarley.com/blog/archive/2004/04/06/507.aspx :

this.statusBar1 .Panels[0].Icon =
Icon.FromHandle (((Bitmap)image List1.Images[0]).GetHicon());

Jan 24 '06 #3
Udi
Thanks Nicholas,
But in which dll resides ImageList_GetIc on() ?
do you have any example of it?
Thanks again!
Udi.

Jan 24 '06 #4
Udi,

You will need to use the P/Invoke layer to make the call. You have to
declare the function like this:

[DllImport("comc tl32.dll", CharSet=CharSet .Auto)]
static extern IntPtr ImageList_GetIc on(IntPtr himl, int i,
[MarshalAs(Unman agedType.U4)] int flags);
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Udi" <Ud**********@g mail.com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
Thanks Nicholas,
But in which dll resides ImageList_GetIc on() ?
do you have any example of it?
Thanks again!
Udi.

Jan 24 '06 #5
The code I posted above works fine for me

Jan 24 '06 #6
Udi
Yup, Chris, for me as well!
Thanks you all!
Udi.

Jan 24 '06 #7

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

Similar topics

6
10509
by: Mohammad-Reza | last post by:
Hi I want to extract icon of an exe file and want to know how. I look at the MSDN and find out that I can use ExtractIconEx() Windows API but in there are some changes to that api in c# I made those changes like this : public static extern uint ExtractIconEx( string szFile,
3
1759
by: Ravi Shankar | last post by:
Hi, I have a windows form application it uses AxShDocVw AxWebBrowser control. The control navigates to web pages at a specified interval set in Timer control. The form uses a notify icon. On axWebBrowser_DocumentComplete event I call a function which calls GetHiCon()(Icons handle). This function works fine for upto to about 2 hrs then the application throws Interop (Generic GDI+ exception). Any idea why this happens. Please excuse me if...
8
1487
by: Dinesh Jain | last post by:
Hi al,, I have written a code which displays directory listing of files from FTP server directory.I display all the files in a listview with its associated icons. To display icons, I get the resouce file name and it's index by searching from the Registry entries. I use ExtractIconsEx() Win32API to extract icon from exe or dll by specifying it's index. I get this error more frequently when I minimize/maximize the window which displays...
0
2855
by: Andre Viens | last post by:
Hello, I am using the following variation of code from <http://support.microsoft.com/default.aspx?scid=kb;EN-US;319340> to add icons to an imagelist for use in a listview: Private Structure SHFILEINFO Public hIcon As IntPtr ' : icon Public iIcon As Integer ' : icondex Public dwAttributes As Integer ' : SFGAO_ flags
2
4639
by: DG78 | last post by:
Hi, In VB 2005, How to extract icons (or images or other resources) from a file ..resx, .resource, .dll or .exe and then to create a new file with this resource (.ico, .jpg ..) ? Thanks Dominique
2
1874
by: Spam Catcher | last post by:
Hi all, Does .NET provide any native API calls to extract .DLL/.EXE icon files based on IconIndex? Is there a way to enumerate through all the icons in an assembly (.NET or Native code assemblies)? Thanks!
2
1568
by: | last post by:
Hello, Can anyone provide me some code snippets, or a class that would allow me to extract icons from an executable file? thank you Learner.
7
2342
by: =?Utf-8?B?QmVu?= | last post by:
Hi I am looking for a way to extraxt an icon from a .exe file an save it as an icon not a bitmap or jpeg to a file? The code below extracts the icon but only as a bitmap PictureBox1.Image = Drawing.Icon.ExtractAssociatedIcon("file.exe").ToBitmap The problem is I need the icon not the bitmap.
0
2357
by: Sathyaish | last post by:
I want to get the icon from an IE shortcut (.url) file without passing a new WebRequest to the server. The .url is an INI file that has the path to the original URI where the icon file resides, but I don't want to make a new web request. Surely the file must be somewhere already on the local system. Is there a way to get it?
0
9079
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8954
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8794
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7626
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5817
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4555
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2234
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1955
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.