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. Can't change icon

Can't change icon

Scheduled Pinned Locked Moved C#
graphicshardwarehelpquestionlearning
6 Posts 4 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.
  • K Offline
    K Offline
    kalkwarf
    wrote on last edited by
    #1

    I am having trouble changing icons. I edit them with the resource editor, but when I display them they haven't changed. For instance, I'll add an icon to my assembly (Add New Item/Icon file). Then I change its Build Action Property to Embedded Resource. Then I edit the default to what I want. I retrieve the icon with: Icon icon = new Icon(this.GetType(), "MyIcon.ico"); Lastly, I assign this icon to the Icon property of a StatusBar panel. The problem is that the icon hasn't changed from the default image. No amount of saving, rebuilding, etc. seems to do anything. Viewing the image in the icon editor shows the changed icon. Viewing the file with a drawing program (e.g Paint) shows the changed icon. I just cannot get it to diaplsy on my form correctly. What am I doing wrong? Dave

    L B E 3 Replies Last reply
    0
    • K kalkwarf

      I am having trouble changing icons. I edit them with the resource editor, but when I display them they haven't changed. For instance, I'll add an icon to my assembly (Add New Item/Icon file). Then I change its Build Action Property to Embedded Resource. Then I edit the default to what I want. I retrieve the icon with: Icon icon = new Icon(this.GetType(), "MyIcon.ico"); Lastly, I assign this icon to the Icon property of a StatusBar panel. The problem is that the icon hasn't changed from the default image. No amount of saving, rebuilding, etc. seems to do anything. Viewing the image in the icon editor shows the changed icon. Viewing the file with a drawing program (e.g Paint) shows the changed icon. I just cannot get it to diaplsy on my form correctly. What am I doing wrong? Dave

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

      Yes, I have had some trouble with that too. An icon may contain several images, typically at different resolutions; typically 16*16 and 32*32 would be present. On Visual Studio 7.1 look at menu Image/Current Icon Image Types. Which image of the icon file gets used depends heavily on circumstances; it may be different for: - the task bar button - the form's icon - Windows Explorer showing small icons - Windows Explorer showing large icons Furthermore, Windows Explorer sometimes caches the icons used in a folder (I am not sure, maybe in Thumbs.db which may be invisible, depends on your settings). So when designing an icon, you should edit all images it contains, and you may want to delete the icon cache file if you can find one. :)

      Luc Pattyn

      K 1 Reply Last reply
      0
      • K kalkwarf

        I am having trouble changing icons. I edit them with the resource editor, but when I display them they haven't changed. For instance, I'll add an icon to my assembly (Add New Item/Icon file). Then I change its Build Action Property to Embedded Resource. Then I edit the default to what I want. I retrieve the icon with: Icon icon = new Icon(this.GetType(), "MyIcon.ico"); Lastly, I assign this icon to the Icon property of a StatusBar panel. The problem is that the icon hasn't changed from the default image. No amount of saving, rebuilding, etc. seems to do anything. Viewing the image in the icon editor shows the changed icon. Viewing the file with a drawing program (e.g Paint) shows the changed icon. I just cannot get it to diaplsy on my form correctly. What am I doing wrong? Dave

        B Offline
        B Offline
        bobsugar222
        wrote on last edited by
        #3

        I think your problem is that you are calling "MyIcon.ico" so it's looking for that file in the current directory. If you are embedding the ico as an ebedded resource it won't be there. You'll need to use Reflection to get the embedded Icon.

        System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
        System.IO.Stream stream = assembly.GetManifestResourceStream("WindowsApplication3.Icon1.ico");
        Icon icon = new Icon(stream);
        this.Icon = icon;

        1 Reply Last reply
        0
        • K kalkwarf

          I am having trouble changing icons. I edit them with the resource editor, but when I display them they haven't changed. For instance, I'll add an icon to my assembly (Add New Item/Icon file). Then I change its Build Action Property to Embedded Resource. Then I edit the default to what I want. I retrieve the icon with: Icon icon = new Icon(this.GetType(), "MyIcon.ico"); Lastly, I assign this icon to the Icon property of a StatusBar panel. The problem is that the icon hasn't changed from the default image. No amount of saving, rebuilding, etc. seems to do anything. Viewing the image in the icon editor shows the changed icon. Viewing the file with a drawing program (e.g Paint) shows the changed icon. I just cannot get it to diaplsy on my form correctly. What am I doing wrong? Dave

          E Offline
          E Offline
          engsrini
          wrote on last edited by
          #4

          if you hav ur icons on the resource manager, it is easy to pic the icons. VS hav some built in functions for that use the following code.. (not tested) statusbar.Icon = global::namespace.Properties.Resources.icon; namespace - give your name space name. icon - name of the image added in the resource manager. hope this helps

          1 Reply Last reply
          0
          • L Luc Pattyn

            Yes, I have had some trouble with that too. An icon may contain several images, typically at different resolutions; typically 16*16 and 32*32 would be present. On Visual Studio 7.1 look at menu Image/Current Icon Image Types. Which image of the icon file gets used depends heavily on circumstances; it may be different for: - the task bar button - the form's icon - Windows Explorer showing small icons - Windows Explorer showing large icons Furthermore, Windows Explorer sometimes caches the icons used in a folder (I am not sure, maybe in Thumbs.db which may be invisible, depends on your settings). So when designing an icon, you should edit all images it contains, and you may want to delete the icon cache file if you can find one. :)

            Luc Pattyn

            K Offline
            K Offline
            kalkwarf
            wrote on last edited by
            #5

            Thank you, this solved most of my problems. I must say that all this is not very intuitive. Multiple icons in one file? Also, it would be nice if the IDE's Icon Editor displayed all the images in the file or gave you a hint that there may be more than one. Oh well. Another question: You mentioned that the icon plucked from the file depends on circumstances. Is there any way of extracting a specific icon from a file? For instance, I get the icon with: statusBarPanel.Icon = new Icon(this.GetType(), "MyIcon.ico"); This seems to look for the 16x16 icon. What if I had a circumstance where I wanted a specific size (color...) rather than the default? Thanks, Dave

            L 1 Reply Last reply
            0
            • K kalkwarf

              Thank you, this solved most of my problems. I must say that all this is not very intuitive. Multiple icons in one file? Also, it would be nice if the IDE's Icon Editor displayed all the images in the file or gave you a hint that there may be more than one. Oh well. Another question: You mentioned that the icon plucked from the file depends on circumstances. Is there any way of extracting a specific icon from a file? For instance, I get the icon with: statusBarPanel.Icon = new Icon(this.GetType(), "MyIcon.ico"); This seems to look for the 16x16 icon. What if I had a circumstance where I wanted a specific size (color...) rather than the default? Thanks, Dave

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

              Well, all those images together form only one icon, so you better make sure they all look alike. I know of no way to pick a specific image from an icon. If you want to pick a specific icon from many, keep them well apart, i.e. in separate files, or in separate resources. BTW there also exists a way to pack multiple icons (each possibly with multiple images) into a single file, I have forgotten all details tho. Maybe its called an icon list ? :)

              Luc Pattyn

              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