MessageBoxDefaultButton 列舉

定義

指定定義 MessageBox 上預設按鈕的常數。

public enum class MessageBoxDefaultButton
public enum MessageBoxDefaultButton
type MessageBoxDefaultButton = 
Public Enum MessageBoxDefaultButton
繼承
MessageBoxDefaultButton

欄位

Button1 0

訊息方塊上的第一個按鈕是預設按鈕。

Button2 256

訊息方塊上的第二個按鈕是預設按鈕。

Button3 512

訊息方塊上的第三個按鈕是預設按鈕。

Button4 768

指定訊息方塊上的 [說明] 按鈕應該是預設按鈕。

範例

下列程式碼範例示範如何使用 這個 多載 Show 所支援的選項來顯示 MessageBox 。 確認字串變數 ServerName 為 空白之後,此範例會顯示 MessageBox 具有問題方塊圖示的 ,為使用者提供取消作業的選項。 此範例會 RightAlign 使用 列舉的成員 MessageBoxOptions ,將文字對齊對話方塊的右邊緣。 Show如果方法的傳回值評估為 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 類別使用。

適用於