Multiple icons from resource

G

Guest

Right now i have embedded an icon file in my project with 6 different
individual icons in it. I currently use

Bitmap icon = new Bitmap(this.GetType(), "App.ico");

to load in the icon but it will only work on the first icon. I've stumbled
upon a class called MultiIcon
(http://www.codeproject.com/dotnet/MultiIcon.asp) which allows you to select
an individual icon. My problem is how to load the resource into this class.
I've added my own constructer in which you can pass a MemoryStream (which is
what the class uses to read the Icon) but i'm unable to get my icon file into
a MemoryStream. I attempted to create a binary formatter and then serialize
it but I kept getting ArgumentNullExceptions in mscorlib.dll. Any help on
this is greatly appreciated.
 
M

Mick Doherty

That is a nice little class.
Change icoStream from type 'IO.MemoryStream' to type 'IO.Stream' and you can
use GetManifestResourceStream().

\\\
System.Reflection.Assembly Assy =
this.GetType().Assembly.GetExecutingAssembly();

thisIcon = new multiIcon(Assy.GetManifestResourceStream(
"myNameSpace.App.ico"))
///

The class would benefit from a ToBitmap method so that 32bit Icons look good
even when not on a Black background. Theres an example of that on my site
(which I may be able to improve on, armed with the info in this class).
http://dotnetrix.co.uk/misc.html
 

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

Top