MessageBoxButtons 列舉

定義

指定要在 MessageBox上顯示哪些按鈕的常數。

public enum class MessageBoxButtons
public enum MessageBoxButtons
type MessageBoxButtons = 
Public Enum MessageBoxButtons
繼承
MessageBoxButtons

欄位

名稱 Description
OK 0

訊息框內有一個確定按鈕。

OKCancel 1

訊息框內有確定和取消按鈕。

AbortRetryIgnore 2

訊息框包含中止、重試和忽略按鈕。

YesNoCancel 3

訊息框包含是、否和取消按鈕。

YesNo 4

訊息框內有「是」和「否」按鈕。

RetryCancel 5

訊息框內有重試和取消按鈕。

CancelTryContinue 6

指定訊息框包含取消、重試及繼續按鈕。

範例

以下程式碼範例說明如何使用 來 MessageBox 讓使用者有機會阻止表單關閉。 此範例要求方法必須從 FormClosing 形式事件中被呼叫。

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

備註

此枚舉由類別使用 MessageBox

適用於

另請參閱