473,396 Members | 1,961 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.

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.Images[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 10941
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_GetIcon 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.com

"Udi" <Ud**********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.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.Images[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)imageList1.Images[0]).GetHicon());

Jan 24 '06 #3
Udi
Thanks Nicholas,
But in which dll resides ImageList_GetIcon() ?
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("comctl32.dll", CharSet=CharSet.Auto)]
static extern IntPtr ImageList_GetIcon(IntPtr himl, int i,
[MarshalAs(UnmanagedType.U4)] int flags);
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Udi" <Ud**********@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Thanks Nicholas,
But in which dll resides ImageList_GetIcon() ?
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
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...
3
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...
8
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...
0
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...
2
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 ...
2
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...
2
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
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 =...
0
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,...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.