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. changing application icon at runtime without recompiling

changing application icon at runtime without recompiling

Scheduled Pinned Locked Moved C#
csharpdebuggingquestion
5 Posts 3 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.
  • G Offline
    G Offline
    GunaChinna
    wrote on last edited by
    #1

    Hi there, I hope that every .net programmer knows about app.ico. If not then create a windows application in c# and check out the working folder. You could see such a file there. This file is the picture file that is displayed in the exe file(check out debug folder of your application). Now what i need is, i want to change this app.ico through c# coding. Is it possible for changing the application icon at runtime without re-compiling? When i mention a .ico file, at runtime, this new .ico file should replace the existing default app.ico file and my .exe file in debug folder should also posses this image. How can this be made?

    R S 2 Replies Last reply
    0
    • G GunaChinna

      Hi there, I hope that every .net programmer knows about app.ico. If not then create a windows application in c# and check out the working folder. You could see such a file there. This file is the picture file that is displayed in the exe file(check out debug folder of your application). Now what i need is, i want to change this app.ico through c# coding. Is it possible for changing the application icon at runtime without re-compiling? When i mention a .ico file, at runtime, this new .ico file should replace the existing default app.ico file and my .exe file in debug folder should also posses this image. How can this be made?

      R Offline
      R Offline
      Rocky
      wrote on last edited by
      #2

      Bitmap bmp = (Bitmap)resources.GetObject("myBMP.bmp"); IntPtr Hicon = bmp.GetHicon(); Icon newIcon = Icon.FromHandle(Hicon); This code here can change ur icon at run time. instead of the first ;line try getting the bmp image from file as for replacing the app.ico well I dont know...

      G 1 Reply Last reply
      0
      • R Rocky

        Bitmap bmp = (Bitmap)resources.GetObject("myBMP.bmp"); IntPtr Hicon = bmp.GetHicon(); Icon newIcon = Icon.FromHandle(Hicon); This code here can change ur icon at run time. instead of the first ;line try getting the bmp image from file as for replacing the app.ico well I dont know...

        G Offline
        G Offline
        GunaChinna
        wrote on last edited by
        #3

        can you please tell me what this 'resources' is- in first line? The error i get with this code is: "The type or namespace name 'resources' could not be found (are you missing a using directive or an assembly reference?)"

        R 1 Reply Last reply
        0
        • G GunaChinna

          can you please tell me what this 'resources' is- in first line? The error i get with this code is: "The type or namespace name 'resources' could not be found (are you missing a using directive or an assembly reference?)"

          R Offline
          R Offline
          Rocky
          wrote on last edited by
          #4

          well lets just forget what that resources was here. Im giving u this actual function that I wrote. public static void change_Icon(string iconName, System.Windows.Forms.Form This) { try { //MessageBox.Show(Environment.CurrentDirectory); string c = Environment.CurrentDirectory; //MessageBox.Show(c + "\n" + c.IndexOf("ATech").ToString() + "\n " + c.Substring(0, (c.IndexOf("ATech") + 6)).ToString()); string path = c.Substring(0, (c.IndexOf("ATech") + 6)) + @"Resources\Icons\" + iconName; Bitmap bmp = new Bitmap(Image.FromFile(path)); IntPtr Hicon = bmp.GetHicon(); Icon newIcon = Icon.FromHandle(Hicon); This.Icon = newIcon; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } well in this I'm just making out the correct path to the resources folder. 'Atech ' is the name of tyhe project and its main directory. The actual images were stored in ......\Atech\Resources\icons folder so I had to get them from there. tell me if u get hold of this code. I think its pretty straight forward. hope it helps Rocky

          1 Reply Last reply
          0
          • G GunaChinna

            Hi there, I hope that every .net programmer knows about app.ico. If not then create a windows application in c# and check out the working folder. You could see such a file there. This file is the picture file that is displayed in the exe file(check out debug folder of your application). Now what i need is, i want to change this app.ico through c# coding. Is it possible for changing the application icon at runtime without re-compiling? When i mention a .ico file, at runtime, this new .ico file should replace the existing default app.ico file and my .exe file in debug folder should also posses this image. How can this be made?

            S Offline
            S Offline
            sno 1
            wrote on last edited by
            #5

            is very simple only you need keep in a loop for instance this: System .Drawing .Icon nuevo=new Icon (@"D:\MyIconNow.ico"); Random manual=new Random (); int p = manual.Next (2); if (p == 1) base.Icon=nuevo; else base.Icon=null; of course, the loop is'nt the only way too keep that atach in execution, try with delegate... if you wanna know anything write me :laugh::laugh::laugh:

            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