MessageBoxDefaultButton 列舉

定義

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

C#
public enum MessageBoxDefaultButton
繼承
MessageBoxDefaultButton

欄位

Button1 0

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

Button2 256

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

Button3 512

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

Button4 768

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

範例

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

C#

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

備註

這項列舉供 MessageBox 類別使用。

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7