MessageBoxOptions 枚举

定义

指定 MessageBox 上的选项。Specifies options on a MessageBox.

此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。

public enum class MessageBoxOptions
[System.Flags]
public enum MessageBoxOptions
type MessageBoxOptions = 
Public Enum MessageBoxOptions
继承
MessageBoxOptions
属性

字段

DefaultDesktopOnly 131072

消息框显示在活动桌面上。The message box is displayed on the active desktop. 此常量类似于 ServiceNotification,但系统仅在交互式窗口工作站的默认桌面上显示消息框。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 也会在当前活动桌面上显示消息框。Show displays a message box on the current active desktop, even if there is no user logged on to the computer.

示例

下面的示例演示如何显示MessageBox的重载支持的选项与MessageBox.Show包括options参数。The following example demonstrates how to display a MessageBox with the options supported by the overloads of MessageBox.Show that include an options parameter. 验证的后的字符串变量, ServerName,是空的该示例显示MessageBox带有问号框图标,为用户提供选项来取消该操作。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. 该示例使用MessageBoxOptions.RightAlign枚举成员,若要将文本与对话框中的右边缘对齐。The example uses the MessageBoxOptions.RightAlign enumeration member to align the text to the right edge of the dialog box. 如果Show方法的返回值的计算结果为DialogResult.Yes,显示的窗体MessageBox已关闭。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

注解

此枚举由 MessageBox 类使用。This enumeration is used by the MessageBox class.

如果您不想指定参数上调用方法时MessageBox,可以改为传递 0 中。If you do not want to specify an argument when calling methods on MessageBox, you can pass in 0 instead.

适用于