MessageBoxButtons Enum

Definisi

Menentukan konstanta yang menentukan tombol mana yang akan ditampilkan pada MessageBox.

public enum class MessageBoxButtons
public enum MessageBoxButtons
type MessageBoxButtons = 
Public Enum MessageBoxButtons
Warisan
MessageBoxButtons

Bidang

AbortRetryIgnore 2

Kotak pesan berisi tombol Batalkan, Coba Lagi, dan Abaikan.

CancelTryContinue 6

Menentukan bahwa kotak pesan berisi tombol Batal, Coba Lagi, dan Lanjutkan.

OK 0

Kotak pesan berisi tombol OK.

OKCancel 1

Kotak pesan berisi tombol OK dan Batal.

RetryCancel 5

Kotak pesan berisi tombol Coba Lagi dan Batalkan.

YesNo 4

Kotak pesan berisi tombol Ya dan Tidak.

YesNoCancel 3

Kotak pesan berisi tombol Ya, Tidak, dan Batal.

Contoh

Contoh kode berikut menunjukkan cara menggunakan MessageBox untuk memberi pengguna kesempatan untuk mencegah formulir ditutup. Contoh ini mengharuskan metode dipanggil dari FormClosing peristiwa formulir.

private:
   void Form1_FormClosing(Object^ sender, FormClosingEventArgs^ e)
   {
      // If the no button was pressed ...
      if ((MessageBox::Show(
         "Are you sure that you would like to close the form?", 
         "Form Closing", MessageBoxButtons::YesNo, 
         MessageBoxIcon::Question) == DialogResult::No))
      {
         // cancel the closure of the form.
         e->Cancel = true;
      }
   }
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    const string message =
        "Are you sure that you would like to close the form?";
    const string caption = "Form Closing";
    var result = MessageBox.Show(message, caption,
                                 MessageBoxButtons.YesNo,
                                 MessageBoxIcon.Question);

    // If the no button was pressed ...
    if (result == DialogResult.No)
    {
        // cancel the closure of the form.
        e.Cancel = true;
    }
}
Private Sub Form1_FormClosing( _
    ByVal sender As System.Object, _
    ByVal e As System.Windows.Forms.FormClosingEventArgs) _
    Handles MyBase.FormClosing

    Dim message As String = _
            "Are you sure that you would like to close the form?"
    Dim caption As String = "Form Closing"
    Dim result = MessageBox.Show(message, caption, _
                                 MessageBoxButtons.YesNo, _
                                 MessageBoxIcon.Question)

    ' If the no button was pressed ...
    If (result = DialogResult.No) Then
        ' cancel the closure of the form.
        e.Cancel = True
    End If
End Sub

Keterangan

Enumerasi ini digunakan oleh MessageBox kelas .

Berlaku untuk

Lihat juga