次の方法で共有


MessageBox.Show メソッド (String, String, MessageBoxButtons, MessageBoxIcon)

指定したテキスト、キャプション、ボタン、およびアイコンを表示するメッセージ ボックスを表示します。

Overloads Public Shared Function Show( _
   ByVal text As String, _   ByVal caption As String, _   ByVal buttons As MessageBoxButtons, _   ByVal icon As MessageBoxIcon _) As DialogResult
[C#]
public static DialogResult Show(stringtext,stringcaption,MessageBoxButtonsbuttons,MessageBoxIconicon);
[C++]
public: static DialogResult Show(String* text,String* caption,MessageBoxButtonsbuttons,MessageBoxIconicon);
[JScript]
public static function Show(
   text : String,caption : String,buttons : MessageBoxButtons,icon : MessageBoxIcon) : DialogResult;

パラメータ

  • text
    メッセージ ボックスに表示するテキスト。
  • caption
    メッセージ ボックスのタイトル バーに表示するテキスト。
  • buttons
    メッセージ ボックスに表示されるボタンを指定する MessageBoxButtons 値の 1 つ。
  • icon
    メッセージ ボックスに表示されるアイコンを指定する MessageBoxIcon 値の 1 つ。

戻り値

DialogResult 値の 1 つ。

例外

例外の種類 条件
InvalidEnumArgumentException 指定した buttons パラメータが、 MessageBoxButtons のメンバではありません。

または

指定した icon パラメータが、 MessageBoxIcon のメンバではありません。

InvalidOperationException ユーザー対話モード以外のモードで実行されているプロセスで、 MessageBox を表示しようとしました。このモードは、 SystemInformation.UserInteractive プロパティで指定されています。

解説

メッセージ ボックスには、最大 3 つのボタンを配置できます。

使用例

[Visual Basic, C#] Show メソッドについては、次のコード例を参照してください。この例を実行するには、次のコードをフォームに貼り付けて、フォームのコンストラクタまたは Load メソッドから InitializeComboBox メソッドを呼び出します。

 

' Declare ComboBox1.
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox

' Initialize ComboBox1.
Private Sub InitializeComboBox()
    Me.ComboBox1 = New ComboBox
    Me.ComboBox1.Location = New System.Drawing.Point(128, 48)
    Me.ComboBox1.Name = "ComboBox1"
    Me.ComboBox1.Size = New System.Drawing.Size(100, 21)
    Me.ComboBox1.TabIndex = 0
    Me.ComboBox1.Text = "Typical"
    Dim installs() As String = New String() _
        {"Typical", "Compact", "Custom"}
    ComboBox1.Items.AddRange(installs)
    Me.Controls.Add(Me.ComboBox1)
End Sub

' Handles the ComboBox1 DropDown event. If the user expands the  
' drop-down box, a message box will appear, recommending the
' typical installation.
Private Sub ComboBox1_DropDown _ 
    (ByVal sender As Object, ByVal e As System.EventArgs) _ 
    Handles ComboBox1.DropDown
    MessageBox.Show("Typical installation is strongly recommended.", _
    "Install information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub

[C#] 

// Declare ComboBox1.
internal System.Windows.Forms.ComboBox ComboBox1;

// Initialize ComboBox1.
private void InitializeComboBox()
{
    this.ComboBox1 = new ComboBox();
    this.ComboBox1.Location = new System.Drawing.Point(128, 48);
    this.ComboBox1.Name = "ComboBox1";
    this.ComboBox1.Size = new System.Drawing.Size(100, 21);
    this.ComboBox1.TabIndex = 0;
    this.ComboBox1.Text    = "Typical";
    string[] installs = new string[]{"Typical", "Compact", "Custom"};
    ComboBox1.Items.AddRange(installs);
    this.Controls.Add(this.ComboBox1);
    
    // Hook up the event handler.
    this.ComboBox1.DropDown +=  
        new System.EventHandler(ComboBox1_DropDown);
}

// Handles the ComboBox1 DropDown event. If the user expands the  
// drop-down box, a message box will appear, recommending the
// typical installation.
private void ComboBox1_DropDown(object sender, System.EventArgs e)
{
    MessageBox.Show("Typical installation is strongly recommended.", 
    "Install information", MessageBoxButtons.OK, 
        MessageBoxIcon.Information);
}

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

.NET Framework セキュリティ:

参照

MessageBox クラス | MessageBox メンバ | System.Windows.Forms 名前空間 | MessageBox.Show オーバーロードの一覧 | MessageBoxButtons | MessageBoxIcon