Using Icons at runtime from resource library!
 
Home My Account Forum Try It! Buy It!
About Contact Us Site Map
StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Using Icons at runtime from resource library!...Expand / Collapse
Author
Message
Posted 07/13/2007 10:01:48 AM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 10/31/2007 5:20:05 PM
Posts: 374, Visits: 1,197
The following is a solution offered by Ben Chase (SF team) that allows you to use icons at runtime from a resource library rather than loading from disk:
the Image and Icon are completely different... mainly because Icon does not inherit from Image (the file formats are completely different since an Icon can have several different sizes within the file). So, I would recommend that you add the icons to your project (not as resources, just add them to the project with the "Add Exisiting Item" option) and change their compile option to Embedded Resource (in the properties for the file). Then, you can use the Icon constructor that accepts a stream to retrieve the embedded resources. Kinda like this:

notifyIcon1.Icon = new Icon(Assembly.GetExecutingAssembly().GetManifestResourceStream("RootNamespace.Folders.FileName"));

C# and VB do some different stuff for the name of the resource when it's compiled. C# uses the root namespace + the folder names separated by "." followed by the filename. Whereas VB just the root namespace + the filename. If you ever want to see what resources are available, you can use the Assembly.GetExecutingAssembly().GetManifestResourceNames(); method which will return the names of all of the resources. Oh, and the names are case-sensitive.

But that's probably your best be for retrieving icons from the assembly at runtime.


..ßen
Post #10267
Posted 07/13/2007 3:28:50 PM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 10/31/2007 5:20:05 PM
Posts: 374, Visits: 1,197
Paul Chase also offered another variation to this solution:
Here is how to accomplish what you originally asked in VB, For C# you would probably just have to change the casting.

NotifyIcon1.Icon = System.Drawing.Icon.FromHandle(CType(Me.ImageList1.Images(0), Drawing.Bitmap).GetHicon)


The following is my own done in C#. Broke it down for clarifications:

Bitmap myBitmap;
IntPtr Hicon;

myBitmap = imageList1.Images["Camera Check.Ico"] as Bitmap;
Hicon = myBitmap.GetHicon();
notifyIcon1.Icon= Icon.FromHandle(Hicon);


..ßen
Post #10285
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 1 (1 guest, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Trent L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 1:14am

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.063. 9 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.