CommonDialog.ShowDialog Method ()
.NET Framework 2.0
Runs a common dialog box with a default owner.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Assembly: System.Windows.Forms (in system.windows.forms.dll)
The following code example uses the ColorDialog implementation of CommonDialog and illustrates creating and showing a dialog box. This example requires that the method is called from within an existing form, which has a TextBox and Button placed on it.
private: void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ ) { ColorDialog^ MyDialog = gcnew ColorDialog; // Keeps the user from selecting a custom color. MyDialog->AllowFullOpen = false; // Allows the user to get help. (The default is false.) MyDialog->ShowHelp = true; // Sets the initial color select to the current text color. MyDialog->Color = textBox1->ForeColor; // Update the text box color if the user clicks OK if ( MyDialog->ShowDialog() == ::DialogResult::OK ) { textBox1->ForeColor = MyDialog->Color; } }
protected void button1_Click(Object sender, System.EventArgs e)
{
ColorDialog myDialog = new ColorDialog();
// Keeps the user from selecting a custom color.
myDialog.set_AllowFullOpen(false);
// Allows the user to get help. (The default is false.)
myDialog.set_ShowHelp(true);
// Sets the initial color select to the current text color.
myDialog.set_Color(textBox1.get_ForeColor());
// Update the text box color if the user clicks OK
if (myDialog.ShowDialog().Equals(get_DialogResult().OK)) {
textBox1.set_ForeColor(myDialog.get_Color());
}
} //button1_Click
- PrintingPermission to print from a PrintDialog. Associated enumeration: PrintingPermissionLevel.SafePrinting
- UIPermission for safe subwindows to call this method. Associated enumeration: UIPermissionWindow.SafeSubWindows
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Community Additions
ADD
Show: