Convert Image to Icon

S

Stanley

I wish to set Form.Icon from an image list but seems like the image list
didn't provide a method to extract the image as an Icon type.

Thus, can anyone show me a way the conversion
From: System.Drawing.Image
To: System.Drawing.Icon

Or show me an easy way to set the Form.Icon from an image list.
Thanks and have a nice day.
 
C

Cor

Hi Stanley,
Did you use the drag method from your toolbox to use the imagelist?
In my opinion that is for this the far out the most simple method.
When you fill with the properties from the designer the imagelist with your
icons, they will be put as bitmaps in the resources.
After you have done that you can bind your image to your controls using the
design properties or dynamicly.
(Therefore I don't have a preference)
Dynamicly you can use the imagelist and imageindex properties to tell what
imagelist has to be used and what is the index.
I hope this helps a little bit.
Cor
 
A

Armin Zingler

Stanley said:
I wish to set Form.Icon from an image list but seems like the image
list didn't provide a method to extract the image as an Icon type.

Thus, can anyone show me a way the conversion
From: System.Drawing.Image
To: System.Drawing.Icon

Or show me an easy way to set the Form.Icon from an image list.
Thanks and have a nice day.

Type-cast the image to Bitmap, then use the bitmap's GetHIcon method to get
the icon handle. Pass it to System.Drawing.Icon.FromHandle
 
H

Herfried K. Wagner [MVP]

Stanley said:
I wish to set Form.Icon from an image list but seems like the image list
didn't provide a method to extract the image as an Icon type.

Thus, can anyone show me a way the conversion
From: System.Drawing.Image
To: System.Drawing.Icon

Or show me an easy way to set the Form.Icon from an image list.

You may want to store the icons as embedded resources instead of an imagelist.

Add the icon file to your project and set its 'Build Action' property to 'Embedded Resource'. You can use the code below to load the icon at runtime:

\\\
foo.Icon = _
New Icon( _
[Assembly].GetExecutingAssembly().GetManifestResourceStream( _
"WindowsApplication1.Ball.ico" _
) _
)
///

'WindowsApplication1' is the root namespace of the application, "Ball.ico"
is the icon's filename.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top