To be a little more specific:
In the Solution Explorer window, right-click on the project you want to add
the dialog to, and select Add->Windows Form from the context menu. You'll
be asked for a name for the new Form's class, and you'll get a blank form
just like when you create a WinForms app, and a new .cs file added to your
project. Add input controls and so forth just like you would for your main
application UI. Add an "OK" button, and make sure that the button's
DialogResult property is set to "OK". Similarly, add a "Cancel" button with
a DialogResult of (surprise surprise) "Cancel".
Now view the code for the dialog's .cs file. In the code editor, add some
public properties for accessing the values in the dialog box's input
controls. You need a "get" accessor on the properties in order to read the
values, but you can also have "set" accessors so that the caller can set
default values for the input controls if necessary. Set accessors are
usually optional, houwver, as in most cases you probably know what a good
default value is ahead of time, and can set that directly through the Forms
Designer.
For example, if your dialog was asking the user for width and height values
for creating a bitmap, you might add something like this:
class myDialog: System.Windows.Forms.Form {
public int Width {
get { return (int)WidthEntry.Value; }
set { WidthEntry.Value = value; }
}
public int Height {
get { return (int)HeightEntry.Value; }
set { HeightEntry.Value = value; }
}
// everything else is what the Forms Designer generated for you
}
In your application, you use it by creating a new "myDialog" object, and
call the ShowDialog() method to display it to the user. After that, treat
it just like you would treat any of the built-in dialogs such as
ColorDialog: check the return value from ShowDialog, get the relevant values
out of the dialog's public fields/properties, and then do whatever you need
to do with them. In this example, maybe something like this:
myDialog d = new myDialog();
if(d.ShowDialog() == DialogResult.OK) {
Bitmap b = new Bitmap(d.Width, d.Height);
}
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:(E-Mail Removed)...
> Creating objects based upon Form is the correct way to make custom
> dialogs.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tipstricks.htm
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/faqmain.htm
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
>
>
> "Mikko Nylén" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> After playing a while with System.Windows.Forms, I decided to try
>> creating my own custom dialogs from scratch. After a bit of googling, I
>> found out that there's not so much examples of doing own custom dialogs.
>>
>> So, I'm asking what is the preferred way for creating your own custom
>> dialogs from scratch? I think it would look a little absurd to inherit
>> Form for a dialog and the only alternative I was able to find was
>> inheriting CommonDialog.
>>
>> The ColorDialog, FontDialog and others inherit from CommonDialog, so I
>> feel like it would be the preferred way. But the problem is that I can't
>> find any examples and the documentation of that class in MSDN isn't so
>> good. For example, when I override RunDialog() and Reset(), what they
>> should actually do? Is there any examples available?
>>
>> Thanks in advance.
>>
>> - Mikko Nylén
>
>