CommonDialog.ShowDialog 方法

定義

執行通用對話方塊。Runs a common dialog box.

多載

ShowDialog()

以預設的擁有人來執行通用對話方塊。Runs a common dialog box with a default owner.

ShowDialog(IWin32Window)

以預設的擁有人來執行通用對話方塊。Runs a common dialog box with the specified owner.

ShowDialog()

以預設的擁有人來執行通用對話方塊。Runs a common dialog box with a default owner.

public:
 System::Windows::Forms::DialogResult ShowDialog();
public System.Windows.Forms.DialogResult ShowDialog ();
member this.ShowDialog : unit -> System.Windows.Forms.DialogResult
Public Function ShowDialog () As DialogResult

傳回

如果使用者在對話方塊中按一下 [確定],則為 OK,否則為 CancelOK if the user clicks OK in the dialog box; otherwise, Cancel.

範例

下列程式碼範例會使用ColorDialogCommonDialog執行, 並說明如何建立和顯示對話方塊。The following code example uses the ColorDialog implementation of CommonDialog and illustrates creating and showing a dialog box. 這個範例會要求從現有的TextBox表單中呼叫方法, 其中包含並Button放在其上。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() == ::System::Windows::Forms::DialogResult::OK )
      {
         textBox1->ForeColor = MyDialog->Color;
      }
   }
private 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;
 }
    
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    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() = Windows.Forms.DialogResult.OK) Then
        TextBox1.ForeColor = MyDialog.Color
    End If
End Sub

備註

這個方法會實作 RunDialogThis method implements RunDialog.

安全性

PrintingPermission
若要從PrintDialog列印。to print from a PrintDialog. 相關聯的列舉:SafePrintingAssociated enumeration: SafePrinting

UIPermission
適用于安全的子視窗來呼叫這個方法。for safe subwindows to call this method. 相關聯的列舉:SafeSubWindowsAssociated enumeration: SafeSubWindows

另請參閱

ShowDialog(IWin32Window)

以預設的擁有人來執行通用對話方塊。Runs a common dialog box with the specified owner.

public:
 System::Windows::Forms::DialogResult ShowDialog(System::Windows::Forms::IWin32Window ^ owner);
public System.Windows.Forms.DialogResult ShowDialog (System.Windows.Forms.IWin32Window owner);
member this.ShowDialog : System.Windows.Forms.IWin32Window -> System.Windows.Forms.DialogResult
Public Function ShowDialog (owner As IWin32Window) As DialogResult

參數

owner
IWin32Window

實作 IWin32Window 的任何物件,代表將擁有強制回應對話方塊的最上層視窗。Any object that implements IWin32Window that represents the top-level window that will own the modal dialog box.

傳回

若使用者在對話方塊中按一下 [確定],則為 OK;否則為 CancelOK if the user clicks OK in the dialog box; otherwise, Cancel.

備註

這個版本的ShowDialog方法可讓您指定將擁有所顯示對話方塊的特定表單或控制項。This version of the ShowDialog method allows you to specify a specific form or control that will own the dialog box that is shown. 如果您使用沒有參數的這個方法版本, 則目前應用程式的使用中視窗會自動擁有所顯示的對話方塊。If you use the version of this method that has no parameters, the dialog box being shown would be owned automatically by the currently active window of your application.

安全性

PrintingPermission
若要從PrintDialog列印。to print from a PrintDialog. 相關聯的列舉:SafePrintingAssociated enumeration: SafePrinting

UIPermission
適用于安全的子視窗來呼叫這個方法。for safe subwindows to call this method. 相關聯的列舉:SafeSubWindowsAssociated enumeration: SafeSubWindows

適用於