共用方式為


MessageBoxButtons 列舉

定義

指定定義那個按鈕要顯示在 MessageBox 上的常數。

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

欄位

AbortRetryIgnore 2

訊息方塊包含 [中止]、[重試] 和 [忽略] 按鈕。

CancelTryContinue 6

指定訊息方塊包含 [取消]、[重試] 和 [繼續] 按鈕。

OK 0

訊息方塊包含 [確定] 按鈕。

OKCancel 1

訊息方塊包含 [確定] 和 [取消] 按鈕。

RetryCancel 5

訊息方塊包含 [重試] 和 [取消] 按鈕。

YesNo 4

訊息方塊包含 [是] 和 [否] 按鈕。

YesNoCancel 3

訊息方塊包含 [是]、[否] 和 [取消] 按鈕。

範例

下列程式碼範例示範如何使用 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 類別使用。

適用於

另請參閱