MessageBoxButtons 列挙型

定義

MessageBoxに表示するボタンを定義する定数を指定します。

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

フィールド

名前 説明
OK 0

メッセージ ボックスに [OK] ボタンが表示されます。

OKCancel 1

メッセージ ボックスに [OK] ボタンと [キャンセル] ボタンが表示されます。

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 クラスによって使用されます。

適用対象

こちらもご覧ください