Export (0) Print
Expand All

MessageBox.Show Method (String, String, MessageBoxButtons, MessageBoxIcon)

.NET Framework 1.1

Displays a message box with specified text, caption, buttons, and icon.

[Visual Basic]
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(
 string text,
 string caption,
 MessageBoxButtons buttons,
 MessageBoxIcon icon
);
[C++]
public: static DialogResult Show(
 String* text,
 String* caption,
 MessageBoxButtons buttons,
 MessageBoxIcon icon
);
[JScript]
public static function Show(
   text : String,
 caption : String,
 buttons : MessageBoxButtons,
 icon : MessageBoxIcon
) : DialogResult;

Parameters

text
The text to display in the message box.
caption
The text to display in the title bar of the message box.
buttons
One of the MessageBoxButtons values that specifies which buttons to display in the message box.
icon
One of the MessageBoxIcon values that specifies which icon to display in the message box.

Return Value

One of the DialogResult values.

Exceptions

Exception Type Condition
InvalidEnumArgumentException The buttons parameter specified is not a member of MessageBoxButtons.

-or-

The icon parameter specified is not a member of MessageBoxIcon.

InvalidOperationException An attempt was made to display the MessageBox in a process that is not running in User Interactive mode. This is specified by the SystemInformation.UserInteractive property.

Remarks

You can have a maximum of three buttons on the message box.

Example

[Visual Basic, C#] The following code example demonstrates the Show method. To run the example, paste the following code in a form and call the InitializeComboBox method from the form's constructor or Load method.

[Visual Basic] 

' 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] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

MessageBox Class | MessageBox Members | System.Windows.Forms Namespace | MessageBox.Show Overload List | MessageBoxButtons | MessageBoxIcon

Show:
© 2014 Microsoft