英語で読む

次の方法で共有


MessageBoxDefaultButton 列挙型

定義

MessageBox に表示する既定のボタンを定義する定数を指定します。

C#
public enum MessageBoxDefaultButton
継承
MessageBoxDefaultButton

フィールド

名前 説明
Button1 0

メッセージ ボックスの 1 番目のボタンが既定のボタンです。

Button2 256

メッセージ ボックスの 2 番目のボタンが既定のボタンです。

Button3 512

メッセージ ボックスの 3 番目のボタンが既定のボタンです。

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, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10