Edit

Share via


MessageBoxButtons Enum

Definition

Specifies constants defining which buttons to display on a MessageBox.

C#
public enum MessageBoxButtons
Inheritance
MessageBoxButtons

Fields

Name Value Description
OK 0

The message box contains an OK button.

OKCancel 1

The message box contains OK and Cancel buttons.

AbortRetryIgnore 2

The message box contains Abort, Retry, and Ignore buttons.

YesNoCancel 3

The message box contains Yes, No, and Cancel buttons.

YesNo 4

The message box contains Yes and No buttons.

RetryCancel 5

The message box contains Retry and Cancel buttons.

CancelTryContinue 6

Specifies that the message box contains Cancel, Try Again, and Continue buttons.

Examples

The following code example shows how to use a MessageBox to give the user an opportunity to prevent a form from closing. This example requires that the method is called from the FormClosing event of the form.

C#
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;
    }
}

Remarks

This enumeration is used by the MessageBox class.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also