Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Assigning an icon to Windows Application

Assigning an icon to Windows Application

Scheduled Pinned Locked Moved C#
helptutorial
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pr teek B h
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • P Pr teek B h

      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

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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:


      P 1 Reply Last reply
      0
      • L Luc Pattyn

        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:


        P Offline
        P Offline
        Pr teek B h
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • P Pr teek B h

          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

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          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:


          P 1 Reply Last reply
          0
          • L Luc Pattyn

            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:


            P Offline
            P Offline
            Pr teek B h
            wrote on last edited by
            #5

            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?

            L 1 Reply Last reply
            0
            • P Pr teek B h

              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?

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              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:


              P 1 Reply Last reply
              0
              • L Luc Pattyn

                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:


                P Offline
                P Offline
                Pr teek B h
                wrote on last edited by
                #7

                Thanks a lot. That was very helpful information. :) Prateek

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups