How to convert a Bitmap to Icon at code level?


Author
Message
Ben Hayat
Ben Hayat
Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
Thank you very much Sir;



Hehe, no not really... 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).
I sadly learned that very quickly (not that I was happy about)



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).
This the way I thought about doing, but didn't know I can "Embed" a resource. I need to look at that.



C# and VB do some different stuff for the name of the resource when it's compiled.
I remember clearly from the class you brought that point up, about the differences in VB and C# and also with the "With" clause!



I'm going to approach it this way. Thanks again.



p.s. Ben if you don't mind, I'm going to put your solution in the new section of samples as a new library of codes. If you don't like it, go ahead and delete it.

..ßen
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Hehe, no not really... 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.

Ben Hayat
Ben Hayat
Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
Here is where I'm running to this issue.



I have a "NotifyIcon" that at runtime, I need to change the icon. But I don't want to grab the icon from disk. So, I placed an "ImageList" and put my Icons in it.



Now when I try to assign one of those images to NotifyIcon.Icon, the compiler complains that the Image from Imagelist is not an "Icon".

notifyIcon1.Icon = imageList1.Images[0];



I've looked around and can't find a way to convert the image from Imagelist to Icon.



Any pointers?

Thanks!

..ßen
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search