Rediger

Del via


MessageBoxOptions Enum

Definition

Specifies options on a MessageBox.

This enumeration supports a bitwise combination of its member values.

public enum class MessageBoxOptions
[System.Flags]
public enum MessageBoxOptions
[<System.Flags>]
type MessageBoxOptions = 
Public Enum MessageBoxOptions
Inheritance
MessageBoxOptions
Attributes

Fields

Name Value Description
DefaultDesktopOnly 131072

The message box is displayed on the active desktop. This constant is similar to ServiceNotification, except that the system displays the message box only on the default desktop of the interactive window station. The application that displayed the message box loses focus, and the message box is displayed without using visual styles. For more information, see Rendering Controls with Visual Styles.

RightAlign 524288

The message box text is right-aligned.

RtlReading 1048576

Specifies that the message box text is displayed with right to left reading order.

ServiceNotification 2097152

The message box is displayed on the active desktop. The caller is a service notifying the user of an event. Show displays a message box on the current active desktop, even if there is no user logged on to the computer.

Examples

The following example demonstrates how to display a MessageBox with the options supported by the overloads of MessageBox.Show that include an options parameter. After verifying that a string variable, ServerName, is empty, the example displays a MessageBox with a question box icon, offering the user the option to cancel the operation. The example uses the MessageBoxOptions.RightAlign enumeration member to align the text to the right edge of the dialog box. If the Show method's return value evaluates to DialogResult.Yes, the form that displayed the MessageBox is closed.

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;
         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();
         }
      }
   }

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();
        }
    }
}
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 = System.Windows.Forms.DialogResult.Yes Then

            ' Closes the parent form.

            Me.Close()

        End If

    End If

End Sub

Remarks

This enumeration is used by the MessageBox class.

If you do not want to specify an argument when calling methods on MessageBox, you can pass in 0 instead.

Applies to