This documentation is archived and is not being maintained.
CommonDialog.ShowDialog Method
.NET Framework 1.1
Runs a common dialog box.
Overload List
Runs a common dialog box with a default owner.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Function ShowDialog() As DialogResult
[C#] public DialogResult ShowDialog();
[C++] public: DialogResult ShowDialog();
[JScript] public function ShowDialog() : DialogResult;
Runs a common dialog box with the specified owner.
[Visual Basic] Overloads Public Function ShowDialog(IWin32Window) As DialogResult
[C#] public DialogResult ShowDialog(IWin32Window);
[C++] public: DialogResult ShowDialog(IWin32Window*);
[JScript] public function ShowDialog(IWin32Window) : DialogResult;
Example
[Visual Basic, C#, C++] The following example uses the ColorDialog implementation of CommonDialog and illustrates creating and showing a dialog box. This example assumes that the method is called from within an existing form, that has a TextBox and Button placed on it.
[Visual Basic, C#, C++] Note This example shows how to use one of the overloaded versions of ShowDialog. For other examples that might be available, see the individual overload topics.
[Visual Basic] Protected Sub button1_Click(sender As Object, e As System.EventArgs) Dim MyDialog As New 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) Then textBox1.ForeColor = MyDialog.Color End If End Sub 'button1_Click [C#] protected void button1_Click(object sender, System.EventArgs e) { ColorDialog MyDialog = new 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; } [C++] protected: void button1_Click(Object* /*sender*/, System::EventArgs* /*e*/) { ColorDialog* MyDialog = new 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; }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
See Also
CommonDialog Class | CommonDialog Members | System.Windows.Forms Namespace
Show: