How to embed icons in a resource?

  • Thread starter Thread starter Morten Wennevik
  • Start date Start date
M

Morten Wennevik

My application has a sysTrayIcon loaded on startup with Icon1.ico
(Embedded resource).

When I pause this application I want sysTrayIcon to show this by swapping
the icon with a greyed out version, but I don't know how to get the
object, or if the object is embedded at all.
At load time I obtain "Icon1.ico" this way:

this.sysTrayIcon.Icon =
((System.Drawing.Icon)(resources.GetObject("sysTrayIcon.Icon")));

but trying either
this.sysTrayIcon.Icon =
((System.Drawing.Icon)(resources.GetObject("Icon2.ico")));
this.sysTrayIcon.Icon =
((System.Drawing.Icon)(resources.GetObject("Icon1.ico")));
fail to load an Icon.

Any idea how to solve this?
 
try to add a class to this assembly, say IconContainter:

namespace MyAssembly {
class IconContainter {
public static Icon GetIcon( string iconName )
{
System.Reflection.Assembly aS = typeof(IconContainter).Assembly;
return new Icon(
aS.GetManifestResourceStream( "MyAssembly." + iconName ) );
}
}
}

regards,
Wiktor
 
Nevermind, I figured it out by using

sysTrayIcon.Icon = new Icon(GetType(), "Icon2.ico");
 
Back
Top