Export (0) Print
Expand All
Expand Minimize

MessageBoxDefaultButton Enumeration

Specifies constants defining the default button on a MessageBox.

[Visual Basic]
<Serializable>
Public Enum MessageBoxDefaultButton
[C#]
[Serializable]
public enum MessageBoxDefaultButton
[C++]
[Serializable]
__value public enum MessageBoxDefaultButton
[JScript]
public
   Serializable
enum MessageBoxDefaultButton

Remarks

This enumeration is used by the MessageBox class.

Members

Member name Description
Button1

Supported by the .NET Compact Framework.

The first button on the message box is the default button.
Button2

Supported by the .NET Compact Framework.

The second button on the message box is the default button.
Button3

Supported by the .NET Compact Framework.

The third button on the message box is the default button.

Example

[Visual Basic] 
Private Sub ValidateUserEntry2()


    ' Checks the value of the text.

    If ServerName.Text.Length = 0 Then

        ' Initializes variables to pass to the MessageBox.Show method.

        Dim Message As String = "You did not enter a server name. Cancel this operation?"
        Dim Caption As String = "No Server Name Specified"
        Dim Buttons As Integer = MessageBoxButtons.YesNo

        Dim Result As DialogResult

        'Displays a MessageBox using the Question icon and specifying the No button as the default.

        Result = MessageBox.Show(Me, Message, Caption, MessageBoxButtons.YesNo, _
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)


        ' Gets the result of the MessageBox display.

        If Result = DialogResult.Yes Then

            ' Closes the parent form.

            Me.Close()

        End If

    End If

End Sub

[C#] 

    private void validateUserEntry2()
    {

        // Checks the value of the text.

        if(serverName.Text.Length == 0)
        {

            // Initializes the variables to pass to the MessageBox.Show method.

            string message = "You did not enter a server name. Cancel this operation?";
            string caption = "No Server Name Specified";
            MessageBoxButtons buttons = MessageBoxButtons.YesNo;
            DialogResult result;

            // Displays the MessageBox.

            result = MessageBox.Show(this, message, caption, buttons,
                MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 
                MessageBoxOptions.RightAlign);

            if(result == DialogResult.Yes)
            {

                // Closes the parent form.

                this.Close();

            }

        }

    }


[C++] 
private:
    void validateUserEntry2() {
        // Checks the value of the text.
        if (serverName->Text->Length == 0) {

            // Initializes the variables to pass to the MessageBox::Show method.
            String* message = S"You did not enter a server name. Cancel this operation?";
            String* caption = S"No Server Name Specified";
            MessageBoxButtons buttons = MessageBoxButtons::YesNo;
            System::Windows::Forms::DialogResult result;

            // Displays the MessageBox.
            result = MessageBox::Show(this, message, caption, buttons,
                MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, 
                MessageBoxOptions::RightAlign);

            if (result == DialogResult::Yes) {
                // Closes the parent form.
                this->Close();
            }
        }
    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

See Also

System.Windows.Forms Namespace

Show:
© 2014 Microsoft