MessageBox.Show Method (String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, Boolean)


Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public static DialogResult Show(
	string text,
	string caption,
	MessageBoxButtons buttons,
	MessageBoxIcon icon,
	MessageBoxDefaultButton defaultButton,
	MessageBoxOptions options,
	bool displayHelpButton


Type: System.String

The text to display in the message box.

Type: System.String

The text to display in the title bar of the message box.

Type: System.Windows.Forms.MessageBoxButtons

One of the MessageBoxButtons values that specifies which buttons to display in the message box.

Type: System.Windows.Forms.MessageBoxIcon

One of the MessageBoxIcon values that specifies which icon to display in the message box.

Type: System.Windows.Forms.MessageBoxDefaultButton

One of the MessageBoxDefaultButton values that specifies the default button for the message box.

Type: System.Windows.Forms.MessageBoxOptions

One of the MessageBoxOptions values that specifies which display and association options will be used for the message box. You may pass in 0 if you wish to use the defaults.

Type: System.Boolean

true to show the Help button; otherwise, false. The default is false.

Return Value

Type: System.Windows.Forms.DialogResult

One of the DialogResult values.

Exception Condition

buttons is not a member of MessageBoxButtons.


icon is not a member of MessageBoxIcon.


The defaultButton specified is not a member of MessageBoxDefaultButton.


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.


options specified both DefaultDesktopOnly and ServiceNotification.


buttons specified an invalid combination of MessageBoxButtons.

A message box is a modal dialog box, which means no input (keyboard or mouse click) can occur except to objects on the modal form. The program must hide or close a modal form (typically in response to some user action) before input to another form can occur.

When the user clicks the Help button, the form that owns the message box (or the active form) receives the HelpRequested event. Handle the HelpRequested event to perform custom Help actions.

The following code example demonstrates how to show a message box with a Help button, handle the Control.HelpRequested event, and show a custom help window in response to the event.

using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
// Display a message box with a Help button. Show a custom Help window
// by handling the HelpRequested event.
private DialogResult AlertMessageWithCustomHelpWindow ()
    // Handle the HelpRequested event for the following message.
    this.HelpRequested += new System.Windows.Forms.HelpEventHandler (this.Form1_HelpRequested);

    this.Tag = "Message with Help button.";

    // Show a message box with OK and Help buttons.
    DialogResult r = MessageBox.Show ("Message with Help button.", 
                                      "Help Caption", MessageBoxButtons.OK, 
                                      0, true);

    // Remove the HelpRequested event handler to keep the event
    // from being handled for other message boxes.
    this.HelpRequested -= new System.Windows.Forms.HelpEventHandler (this.Form1_HelpRequested);

    // Return the dialog box result.
    return r;

private void Form1_HelpRequested (System.Object sender, System.Windows.Forms.HelpEventArgs hlpevent)
    // Create a custom Help window in response to the HelpRequested event.
    Form helpForm = new Form ();

    // Set up the form position, size, and title caption.
    helpForm.StartPosition = FormStartPosition.Manual;
    helpForm.Size = new Size (200, 400);
    helpForm.DesktopLocation = new Point (this.DesktopBounds.X + 
    helpForm.Text = "Help Form";

    // Create a label to contain the Help text.
    Label helpLabel = new Label ();

    // Add the label to the form and set its text.
    helpForm.Controls.Add (helpLabel);
    helpLabel.Dock = DockStyle.Fill;

    // Use the sender parameter to identify the context of the Help request.
    // The parameter must be cast to the Control type to get the Tag property.
    Control senderControl = sender as Control;

    helpLabel.Text = "Help information shown in response to user action on the '" + 
                      (string)senderControl.Tag + "' message.";

    // Set the Help form to be owned by the main form. This helps
    // to ensure that the Help form is disposed of.
    this.AddOwnedForm (helpForm);

    // Show the custom Help window.
    helpForm.Show ();

    // Indicate that the HelpRequested event is handled.
    hlpevent.Handled = true;


for safe subwindows to call this method. Associated enumeration: UIPermissionWindow.SafeSubWindows

.NET Framework
Available since 2.0
Return to top