MessageBoxOptions 枚举

定义

指定 MessageBox上的选项。

此枚举支持其成员值的按位组合。

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

字段

名称 说明
DefaultDesktopOnly 131072

消息框显示在活动桌面上。 此常量类似于 ServiceNotification,只是系统仅在交互式窗口工作站的默认桌面上显示消息框。 显示消息框的应用程序将失去焦点,并且显示消息框时不使用视觉样式。 有关详细信息,请参阅 使用视觉样式呈现控件

RightAlign 524288

消息框文本右对齐。

RtlReading 1048576

指定消息框文本以从右到左的阅读顺序显示。

ServiceNotification 2097152

消息框显示在活动桌面上。 调用方是通知用户事件的服务。 Show 显示当前活动桌面上的消息框,即使没有用户登录到计算机。

示例

以下示例演示如何显示MessageBox包含MessageBox.Show参数的options重载支持的选项。 验证字符串变量是否 ServerName为空后,该示例会显示一个 MessageBox 带有问题框图标的选项,为用户提供取消操作的选项。 该示例使用 MessageBoxOptions.RightAlign 枚举成员将文本与对话框的右边缘对齐。 Show如果方法的返回值计算结果为DialogResult.Yes,则显示MessageBox该方法的窗体已关闭。

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 类使用。

如果不想在调用方法 MessageBox时指定参数,可以改为传入 0。

适用于