Windows Forms ships with several standard dialogs (sometimes known as "common dialogs") provided as components located in the System.Windows.Forms namespace. Here's how to manually create and show an instance of a dialog component like ColorDialog: // ColorDialogForm.cs partial class ColorDialogForm : Form { ... void colorDialogButton_Click(object sender, EventArgs e) { ColorDialog dlg = new ColorDialog(); dlg.Color = Color.Red; DialogResult result = dlg.ShowDialog(); if( result == DialogResult.OK ) { MessageBox.Show("You picked " + dlg.Color.ToString()); } } } However, the common dialog components are also located on the Toolbox in VS05, and this means that you can drag them onto a form and configure them from the Properties window. This allows you to show them without writing the initialization code manually: // ColorDialogForm.Designer.cs partial class ColorDialogForm { ... void InitializeComponent() { ... this.colorDialog.Color = System.Drawing.Color.Red; ... } } // ColorDialogForm.cs partial class ColorDialogForm : Form { public ColorDialogForm() { InitializeComponent(); } void colorDialogButton_Click(object sender, EventArgs e) { DialogResult result = colorDialog.ShowDialog(); if( result == DialogResult.OK ) { MessageBox.Show( "You picked " + this.colorDialog.Color.ToString()); } } } I tend to prefer the latter approach because I like to set properties like Color visually with the Properties window, which you'll notice is also stored in InitializeComponent, thereby saving you the coding. But either approach works just fine. The following standard dialogs come with Windows Forms:[1]
Excluding PrintPreviewDialog, the standard dialogs are wrappers around existing common dialogs in Windows. Because these dialogs don't support modeless operation, neither do the Windows Forms components. However, PrintPreviewDialog provides a new dialog and supports both modal and modeless operation using ShowDialog and Show, respectively. |