Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

CommonDialog Class

Specifies the base class used for displaying dialog boxes on the screen.

For a list of all members of this type, see CommonDialog Members.

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Windows.Forms.CommonDialog
            Derived classes

[Visual Basic]
MustInherit Public Class CommonDialog
   Inherits Component
[C#]
public abstract class CommonDialog : Component
[C++]
public __gc __abstract class CommonDialog : public Component
[JScript]
public abstract class CommonDialog extends Component

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

Inheritied classes are required to implement RunDialog by invoking ShowDialog to create a specific common dialog box. Inherited classes can optionally override HookProc to implement specific dialog box hook functionality.

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] 
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 Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

See Also

CommonDialog Members | System.Windows.Forms Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.