Can I change the default icon used on a Winform?
Most of my forms have their icon property set to a custom icon. For the few forms that slip through the cracks, I don't want the generic "hey look, he made this in visual studio" icon.
One solution is to tediously check every one of my forms to make sure they either have a custom icon set or have ShowIcon set to False.
Another solution is to have every one of my forms inherit from a base class that sets a custom icon in the constructor.
Aside from those solutions, what other options do I have?
EDIT:
I was hoping there would be a way to replace the source of the stock icon with my own. Is it in a resource file somewhere? Or is it embedded in a .NET dll that I can't (or really, really shouldn't) modify?
BOUNTY EDIT:
Is there a way to accomplish this without editing or writing a single line of code? I don't care how impractical, complicated, waste-of-time the solution is… I just want to know if it's possible. I need to satisfy my curiosity.
Best Answer
The default icon is embedded in the winforms dll - looking at reflector (
DefaultIcon
) it is:There is no magic in there that checks another common location, so you can't do it without changing code.
You could always embrace the forces of darkness with field-based reflection? Note: this is hacky and brittle. On your own head! But it works:
To do it properly; two common options;
Form
class which has the icon setForm
method - perhaps something like:code:
Then instead of:
Something like:
Of course - that isn't much prettier! Another option might be a C# 3.0 extension method, perhaps as a fluent API:
and
This is then just a
.CommonInit()
away from your existing code.