Assigning an icon to Windows Application
-
Hi I am creating an application through which the user can select a mode and that will change the icon. I have added different icons to my project but don't know how to change the icon. Note: What I'm trying to do is not the same as going into properties in visual studios and changing the icon. Any help would be great. Thanks, Prateek
-
Hi I am creating an application through which the user can select a mode and that will change the icon. I have added different icons to my project but don't know how to change the icon. Note: What I'm trying to do is not the same as going into properties in visual studios and changing the icon. Any help would be great. Thanks, Prateek
Hi, a file has an icon in Windows Explorer; for an EXE file that icon is set at build time through the project properties. a Form most often has a visible icon in the title bar; that one is set through the Icon property of the Form, either through Visual Designer or by run-time code. It is also used in the task bar and in the task switcher (ALT-TAB). You would typically add one or more ICO files to the project, set them to be handled as an "embedded resource", then load them from there e.g. with the Icon constructor that takes a Type and a resource name. You can also see how Visual Designer does it, and copy and adapt that code. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
-
Hi, a file has an icon in Windows Explorer; for an EXE file that icon is set at build time through the project properties. a Form most often has a visible icon in the title bar; that one is set through the Icon property of the Form, either through Visual Designer or by run-time code. It is also used in the task bar and in the task switcher (ALT-TAB). You would typically add one or more ICO files to the project, set them to be handled as an "embedded resource", then load them from there e.g. with the Icon constructor that takes a Type and a resource name. You can also see how Visual Designer does it, and copy and adapt that code. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
you mean
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
but, what is "$this.Icon" referring to? and from where can I change the location of the icon? Prateek
-
you mean
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
but, what is "$this.Icon" referring to? and from where can I change the location of the icon? Prateek
No, first use Visual Designer to assign some icon to the Form other than the application icon (that is the default and generates the line you quoted). Then look at the VD code and work from there. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
-
No, first use Visual Designer to assign some icon to the Form other than the application icon (that is the default and generates the line you quoted). Then look at the VD code and work from there. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
That's exactly what I did and found this code in the designer.
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
I also tried looking for the filename, but couldn't find it. :( Where should I be looking? and/or what should I do now?
-
That's exactly what I did and found this code in the designer.
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
I also tried looking for the filename, but couldn't find it. :( Where should I be looking? and/or what should I do now?
Sorry, I got confused about resources once more. 1. The icon you assign to Form myForm using VD gets stored in file myForm.resx, and the $this then refers to myForm. 2. This is the code you need to activate an embedded icon resource (Build Action=embedded resource) in general:
this.Icon=new Icon(this.GetType(), "name.ico");
assuming the file is at the top-level of your solution. If you put it in say directory
resources
, then the name changes to"resources.name.ico"
:)Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
-
Sorry, I got confused about resources once more. 1. The icon you assign to Form myForm using VD gets stored in file myForm.resx, and the $this then refers to myForm. 2. This is the code you need to activate an embedded icon resource (Build Action=embedded resource) in general:
this.Icon=new Icon(this.GetType(), "name.ico");
assuming the file is at the top-level of your solution. If you put it in say directory
resources
, then the name changes to"resources.name.ico"
:)Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
Thanks a lot. That was very helpful information. :) Prateek