473,564 Members | 2,749 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 10985
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
10501
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
1758
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...
8
1480
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...
0
2830
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
4628
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
1871
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
1564
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
2337
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
2353
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
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8108
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...
1
7644
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...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6260
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...
1
2083
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
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
925
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...

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.