Hi
I´m writing simple win apps with text editor. How do I give my form a new icon?
I know how to give the .exe file icon with the command line.
I need the form icon to be embedded in the exe file and not loaded
from an extenal .ico on start.
tia
H
Loading
AlanPosted Feb 3, 2008, 5:39 PM
If you're using a text editor to write your applications, I imagine you must be using the command line compiler, csc.exe., and not an IDE (VS or SharpDevelop) as Scott assumed.
If your source file is called myapp.cs and your icon file, myicon.ico, is in the same directory, then you need the following command line to embed it as a resource within the .exe:
csc /t:winexe /resource:myicon.ico myapp.cs
If your main form is called Form1, you also need to place the following line in Form1's constructor before compiling the file:
this.Icon = new System.Drawing.Icon(typeof(Form1), "myicon.ico");
Scott LyslePosted Feb 3, 2008, 4:27 PM
The easiest way to do it would be to set the form's icon property from the IDE; this will setup the icon as a resource and add the appropriate lines to the form's designer:
e.g.:
this
.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));