Bahasa

CommonDialog.ShowDialog Metode

Definisi

Menjalankan kotak dialog umum.

Overload

Nama Deskripsi
ShowDialog()

Menjalankan kotak dialog umum dengan pemilik default.

ShowDialog(IWin32Window)

Menjalankan kotak dialog umum dengan pemilik yang ditentukan.

ShowDialog()

Sumber:
CommonDialog.cs
Sumber:
CommonDialog.cs
Sumber:
CommonDialog.cs
Sumber:
CommonDialog.cs
Sumber:
CommonDialog.cs

Menjalankan kotak dialog umum dengan pemilik default.

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

Mengembalikan

OK jika pengguna mengklik OK dalam kotak dialog; jika tidak, Cancel.

Contoh

Contoh kode berikut menggunakan ColorDialog implementasi CommonDialog dan mengilustrasikan pembuatan dan memperlihatkan kotak dialog. Contoh ini mengharuskan metode dipanggil dari dalam formulir yang ada, yang memiliki TextBox dan Button ditempatkan di atasnya.

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() = DialogResult.OK) Then
        TextBox1.ForeColor = MyDialog.Color
    End If
End Sub

Keterangan

Metode ini mengimplementasikan RunDialog.

Lihat juga

Berlaku untuk

ShowDialog(IWin32Window)

Sumber:
CommonDialog.cs
Sumber:
CommonDialog.cs
Sumber:
CommonDialog.cs
Sumber:
CommonDialog.cs
Sumber:
CommonDialog.cs

Menjalankan kotak dialog umum dengan pemilik yang ditentukan.

public:
 System::Windows::Forms::DialogResult ShowDialog(System::Windows::Forms::IWin32Window ^ 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

Parameter

owner
IWin32Window

Objek apa pun yang mengimplementasikan IWin32Window yang mewakili jendela tingkat atas yang akan memiliki kotak dialog modal.

Mengembalikan

OK jika pengguna mengklik OK dalam kotak dialog; jika tidak, Cancel.

Keterangan

Versi ShowDialog metode ini memungkinkan Anda menentukan formulir atau kontrol tertentu yang akan memiliki kotak dialog yang ditampilkan. Jika Anda menggunakan versi metode ini yang tidak memiliki parameter, kotak dialog yang ditampilkan akan dimiliki secara otomatis oleh jendela aktif aplikasi Anda saat ini.

Berlaku untuk