語言

MessageBoxOptions 列舉

定義

指定 MessageBox上的選項。

此列舉支援其成員值的位元組合。

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

欄位

名稱 值 Description
DefaultDesktopOnly 131072

訊息框會顯示在活躍的桌面上。 此常數與 類似 ServiceNotification,但系統僅在互動視窗工作站的預設桌面上顯示訊息框。 顯示訊息框的應用程式會失去焦點,訊息框在沒有使用視覺風格的情況下顯示。 欲了解更多資訊,請參閱 「以視覺樣式渲染控制」。

RightAlign 524288

訊息框文字是右對齊的。

RtlReading 1048576

規定訊息框文字依右至左閱讀順序顯示。

ServiceNotification 2097152

訊息框會顯示在活躍的桌面上。 呼叫者是一個通知使用者事件的服務。 Show 即使沒有使用者登入電腦,仍會在當前活躍桌面上顯示訊息框。

範例

以下範例示範如何顯示 aMessageBox,並包含參數的超載MessageBox.Showoptions選項。 在確認字串變數 ServerName為空後,範例會顯示帶有問題框圖示的 a 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。

適用於