How do I change the icon on the dialog?
-
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:
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 itsShowDialog()
method. -
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 itsShowDialog()
method.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
-
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
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:
-
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:
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?