MessageBoxButtons 枚举

定义

指定若干常数,用以定义 MessageBox 上将显示哪些按钮Specifies constants defining which buttons to display on a MessageBox.

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

字段

AbortRetryIgnore 2

消息框包含“中止”、“重试”和“忽略”按钮。The message box contains Abort, Retry, and Ignore buttons.

OK 0

消息框包含“确定”按钮。The message box contains an OK button.

OKCancel 1

消息框包含“确定”和“取消”按钮。The message box contains OK and Cancel buttons.

RetryCancel 5

消息框包含“重试”和“取消”按钮。The message box contains Retry and Cancel buttons.

YesNo 4

消息框包含“是”和“否”按钮。The message box contains Yes and No buttons.

YesNoCancel 3

消息框包含“是”、“否”和“取消”按钮。The message box contains Yes, No, and Cancel buttons.

示例

下面的代码示例演示如何使用MessageBox来向用户显示防止窗体关闭的机会。The following code example shows how to use a MessageBox to give the user an opportunity to prevent a form from closing. 此示例要求从窗体的FormClosing事件中调用方法。This example requires that the method is called from the FormClosing event of the form.

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 类使用。This enumeration is used by the MessageBox class.

适用于

另请参阅