Dear All,
I am new programming in c#, the first programs I am developing are not too big and I am developing them by hand, it means I am not using the VS wizzards. I compile the applications (console or winapp) from the command line. My problem is that I don't know how to change the default Icon of a Form and including it in the exe file. I mean I know that I have to use :
this.Icon = new Icon("myicon.ico");
to assign the Icon. The application works if I have the file myicon.ico in the same directory as the application but if I try to execute the application in another directory it crashes because it doesn't find the icon file, it produces a portability problem, I have already try with other code like:
Icon icon1 = (System.Drawing.Icon)this.FormResources.GetObject("myicon.ico");
or
Stream strm = (Stream) Assembly.GetExecutingAssembly().GetManifestResourceStream("myicon.ico");
this.Icon = new Icon(strm); <-- this didn't work I found the example in internet but I don't know if the type stream is correct to define an Icon.
and always I get the same problem or a worse one.
what ever, now I am lost in a cycle and I ask for your help may be the solution is not so complicated, but I would appreciate the replies and if someone help me to solve the problem.
thank you very much in advance
desperate Oriana
Loading
ty JiangPosted Jun 4, 2012, 11:40 PM
Your can change your code to,
this.Icon = Properties.Resources.myIcon;
Oriana GonzalezPosted Oct 6, 2009, 3:41 PM
thanks a lot for your Reply, I tried also that code, it assigns a new Icon to the .exe file. But what I mean is the default windows icon on the top of the window at the left corner. I defined the form property with:
this.Icon = new Icon("myIcon.ico");
and I can see the Icon in the right position in the form, but If I copy the .exe file in other location the application crashes because it doesn't find the Icon file, it means that I have to copy the Icon in the same directory as the .exe file. But I can not request every user of my application to copy both files. the .exe and the .ico, I think there is a better way to compile the Icon togehter with the application to include it in the .exe unfortunately I haven't found the right bibliografy to do it, I hope you or someone of the forum can help me to solve this problem.
thank you very much in advance:
Oriana
Roei BarPosted Oct 6, 2009, 2:37 PM
just select your icon and thats it
and if you want to compile via Command line
add this
/win32icon: