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. .NET (Core and Framework)
  4. How do I change the icon on the dialog?

How do I change the icon on the dialog?

Scheduled Pinned Locked Moved .NET (Core and Framework)
question
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.
  • A Offline
    A Offline
    adonisv
    wrote on last edited by
    #1

    I know somewhere in the code the dialog is told which icon to load and display. Does anyone know where that code is? How can I supply my own custom icon to display on my dialogs? :doh:

    M 1 Reply Last reply
    0
    • A adonisv

      I know somewhere in the code the dialog is told which icon to load and display. Does anyone know where that code is? How can I supply my own custom icon to display on my dialogs? :doh:

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      You could always create your own dialog forms by subclassing System.Windows.Forms.Form, including your own icon on it, then showing an instance of it using its ShowDialog() method.

      D 1 Reply Last reply
      0
      • M Mike Ellison

        You could always create your own dialog forms by subclassing System.Windows.Forms.Form, including your own icon on it, then showing an instance of it using its ShowDialog() method.

        D Offline
        D Offline
        Dan Broomall
        wrote on last edited by
        #3

        Let me make sure I understand the question before I say something stupid. You have created a custom dialog and you want to change the icon for that dialog. Correct? If so, then you should be able to simply change the Icon property of the dialog. It should simply be a matter of mapping to the Icon file that you would like to use. For simplicity, you could add the Icon to your project, then you won't have to worry about validating whether the file exists or not. It will be a part of your solution. Is this what you meant? Dan

        A 1 Reply Last reply
        0
        • D Dan Broomall

          Let me make sure I understand the question before I say something stupid. You have created a custom dialog and you want to change the icon for that dialog. Correct? If so, then you should be able to simply change the Icon property of the dialog. It should simply be a matter of mapping to the Icon file that you would like to use. For simplicity, you could add the Icon to your project, then you won't have to worry about validating whether the file exists or not. It will be a part of your solution. Is this what you meant? Dan

          A Offline
          A Offline
          adonisv
          wrote on last edited by
          #4

          I thought I did that. :confused: I only have one icon in my project and I can't see where the code is loading it into the dialog. It MUST BE somewhere. There's that stupid default icon with the three cubes. That's no longer visible. Now I have a "dialog" icon which must be the default icon if the three cubes are not available. I know it can be done because in one of our other appilications the custom icon is showing. Maybe I'll just look at that one. I was hoping there was an easier answer. :sigh:

          D 1 Reply Last reply
          0
          • A adonisv

            I thought I did that. :confused: I only have one icon in my project and I can't see where the code is loading it into the dialog. It MUST BE somewhere. There's that stupid default icon with the three cubes. That's no longer visible. Now I have a "dialog" icon which must be the default icon if the three cubes are not available. I know it can be done because in one of our other appilications the custom icon is showing. Maybe I'll just look at that one. I was hoping there was an easier answer. :sigh:

            D Offline
            D Offline
            Dan Broomall
            wrote on last edited by
            #5

            Okay. I just ran a test of this and I have found two specific ways of doing this (although I am sure there are more out there). I created a project and added two different looking icons. The first I went into the form's properties and changed the icon there. The mis-leading part is that even though your icons are loaded as "part" of your project/solution, you will still have to reference them by path and filename. So, I set one of them at design time to make sure that worked. It did. Once this was successful, I went into the Form1_Load procedure and created an object of type System.Drawing.Icon. This has 6 different constructors, one of which accepts a path/filename. I created that and passed it "..\Icon2.ico" as the path/filename (.. because the root for execution is bin and I had the file in the main project directory). I then simply set the Me.Icon property to the Icon object I had just created. All tests were successful. Does this make sense?

            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