By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,682 Members | 1,368 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,682 IT Pros & Developers. It's quick & easy.

Convert Image to Icon

P: n/a
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.
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
Nov 20 '05 #2

P: n/a
"Stanley" <se****@email.com> schrieb
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
--
Armin

Nov 20 '05 #3

P: n/a
"Stanley" <se****@email.com> scripsit:
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.

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.