How to retreive the application Icon

  • Thread starter Thread starter Wayne
  • Start date Start date
W

Wayne

I currently have an app whose Icon I am setting. I want to set the icons in
my forms at run time to that of the application icon. How do I retrieve the
application Icon so that I can use it for my forms? once retrieved can I
just set the form Icon? or do I need to do something special?

Thanks
Wayne
 
Wayne,

I would create a class with a static member which would return the icon
when called. Then, all of your forms would access this static method to set
the icon that it should have. Where you get this icon is up to you (you can
get it from a resource file, etc, etc).

Hope this helps.
 
I don't really want to do it that way, I currently have some plugins that
may or may not display forms when they are shown. I'd like to be able to
have the plugin query information from the main assembly to get the Icon.
Not to mentioned I'd like to figure out how to do it.

Thanks
Wayne



Nicholas Paldino said:
Wayne,

I would create a class with a static member which would return the icon
when called. Then, all of your forms would access this static method to set
the icon that it should have. Where you get this icon is up to you (you can
get it from a resource file, etc, etc).

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Wayne said:
I currently have an app whose Icon I am setting. I want to set the icons in
my forms at run time to that of the application icon. How do I retrieve the
application Icon so that I can use it for my forms? once retrieved can I
just set the form Icon? or do I need to do something special?

Thanks
Wayne
 
Wayne

If you are referring to the App.ico resource that the wizard supplies, you
can compile the App icon as an embedded resource - then create a static
method as Nicholas suggested to return a reference to the Icon object. In
Solution Explorer, right click on the icon resource, select Properties, and
change the Build Action to Embedded Resource. Then to get the icon resource
into an Icon object, try something like this in the main method of your app:

static void Main()
{
myIcon = new Icon(typeof(Form1),"MY_ICON.ICO");
/* do something with myIcon here... */
Application.Run(new Form1());
}

You can easily add icons and include them as resources in the assembly using
the IDE Add|Existing Item, browsing to the file that contains the .ico
resource, and then changing the Build Action to Embedded Resource.

Note - the icon resource name is case sensitive in the Icon constructor...

regards
roy fine
 
Back
Top