[ACCEPTED]-Where to find the default Winforms icon in Windows?-icons
It is stored as a resource in the System.Windows.Forms.dll 8 assembly. You could get a copy with Reflector. Open 7 the assembly, open the Resources node, all 6 the way down to "wfc.ico". Right-click, Save 5 As. Not sure why you'd want to use it, given 4 that it is the default.
You set a custom 3 icon for your application with Project + Properties, Application 2 tab, Icon setting. Each form has its own 1 Icon property.
If you have Visual Studio 2010 installed 17 then there is a large collection of icons 16 (potentially including the application icon/s), check 15 out the following directory:
%ProgramFiles%\Microsoft Visual Studio 10.0\Common7\VS2010ImageLibrary\1033
There may be 14 a similar directory for previous VS versions, take 13 a look if needs be.
EDIT:
On doing a search 12 in the folder of the unzipped file for app
there 11 are two notable results:
Application.ico and ApplicationGeneric.ico + its *.png 10 counterpart.
If you have VS 2010 and any 9 of the icons in here are suitable, I believe 8 you don't need to copy a single one - you 7 should be able to include the file indirectly 6 (as a shared/linked file) when adding using 5 the Existing Item...
dialog; you do this by selecting the 4 arrow next to Add
button and selecting the 3 Add As Link
option.
What I can't see working as desired 2 is simply overwriting these files in an 1 attempt to apply a global change.
It is stored as a resource in the System.Windows.Forms.dll 10 assembly. You could get a copy with reflection 9 as folow:
public static class FormUtils
{
private static Icon _defaultFormIcon;
public static Icon DefaultFormIcon
{
get
{
if (_defaultFormIcon == null)
_defaultFormIcon = (Icon)typeof(Form).
GetProperty("DefaultIcon", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).GetValue(null, null);
return _defaultFormIcon;
}
}
public static void SetDefaultIcon()
{
var icon = Icon.ExtractAssociatedIcon(EntryAssemblyInfo.ExecutablePath);
typeof(Form)
.GetField("defaultIcon", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)
.SetValue(null, icon);
}
}
public static class FormExtensions
{
internal static void GetIconIfDefault(this Form dest, Form source)
{
if (dest.Icon == FormUtils.DefaultFormIcon)
dest.Icon = source.Icon;
}
}
So as you can see in the code you 8 have in this way the same Icon.Handle. The 7 same reference. Form.DefaultIcon is an internal 6 lazy loaded static property in class Form.
You 5 can also override the default Winforms icon 4 for your application. In Program.cs i use:
FormUtils.SetDefaultIcon();
This 3 function will then override the default 2 icon with the icon specified in your Application 1 properties, the icon of your executable.
You can just use the Save
method:
C#:
string IcoFilename = "C:\\Junk\\Default.ico";
using (System.IO.FileStream fs = new System.IO.FileStream(IcoFilename, System.IO.FileMode.Create))
{
this.Icon.Save(fs);
}
Visual Basic:
Dim strFilename As String = "C:\Junk\Default.ico"
Using fs As New System.IO.FileStream(strFilename, IO.FileMode.Create)
Me.Icon.Save(fs)
End Using
0
I had a problem which was similar, but different. Rather 5 than needing to get the default icon, I 4 needed to check to see whether the icon 3 on a form was set or if it was left as the 2 default. While I could have used reflection 1 to get it, I ended up using a simpler solution:
private static Icon defaultIcon = new Form().Icon;
// ...
if(this.Icon == defaultIcon)
{
// ...
}
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.