PC Review


Reply
Thread Tools Rate Thread

Convert Image to Icon

 
 
Stanley
Guest
Posts: n/a
 
      4th Oct 2003
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.


 
Reply With Quote
 
 
 
 
Cor
Guest
Posts: n/a
 
      4th Oct 2003
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


 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      4th Oct 2003
"Stanley" <(E-Mail Removed)> 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

 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      4th Oct 2003
"Stanley" <(E-Mail Removed)> 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>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Icon to Image File fripper Windows XP General 3 15th Apr 2006 11:53 PM
Create Icon from image convert OliverS Windows XP General 2 30th Dec 2005 04:10 PM
Re: Convert image into icon Alex Nichol Windows XP General 0 5th Aug 2004 02:10 PM
Referencing an embedded icon, convert to image? news.microsoft.com Microsoft VB .NET 4 11th Apr 2004 02:07 AM
Howto Convert Icon to Image Dirk Ströker Microsoft Dot NET Framework Forms 2 24th Nov 2003 08:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:05 PM.