Export (0) Print
Expand All
Expand Minimize

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

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

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,
	string helpFilePath,
	string keyword
)
public static DialogResult Show (
	String text, 
	String caption, 
	MessageBoxButtons buttons, 
	MessageBoxIcon icon, 
	MessageBoxDefaultButton defaultButton, 
	MessageBoxOptions options, 
	String helpFilePath, 
	String keyword
)
public static function Show (
	text : String, 
	caption : String, 
	buttons : MessageBoxButtons, 
	icon : MessageBoxIcon, 
	defaultButton : MessageBoxDefaultButton, 
	options : MessageBoxOptions, 
	helpFilePath : String, 
	keyword : String
) : DialogResult
Not applicable.

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.

defaultButton

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

options

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.

helpFilePath

The path and name of the Help file to display when the user clicks the Help button.

keyword

The Help keyword to display when the user clicks the Help button.

Return Value

One of the DialogResult values.

Exception typeCondition

InvalidEnumArgumentException

buttons is not a member of MessageBoxButtons.

-or-

icon is not a member of MessageBoxIcon.

-or-

The defaultButton specified is not a member of MessageBoxDefaultButton.

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.

ArgumentException

options specified both DefaultDesktopOnly and ServiceNotification.

-or-

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 Help file specified in the helpFilePath parameter is opened and the Help keyword topic identified by the keyword parameter is displayed. The form that owns the message box (or the active form) also receives the HelpRequested event.

The following code example demonstrates how to show a message box with a Help button. When the user clicks the Help button, the Mspaint.chm Help file is opened and the topic identified by the mspaint.chm::/paint_brush.htm keyword is displayed. The example requires that the Mspaint.chm Help file is installed.

using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;

	...

            // Display a message box. The Help button opens the Mspaint.chm Help file, 
            // and the "mspaint.chm::/paint_brush.htm" Help keyword shows the 
            // associated topic.
            DialogResult r7 = MessageBox.Show ("Message with Help file and keyword.", 
                                               "Help Caption", MessageBoxButtons.OK, 
                                               MessageBoxIcon.Question, 
                                               MessageBoxDefaultButton.Button1, 0, 
                                               "mspaint.chm", 
                                               "mspaint.chm::/paint_brush.htm");

package WindowsApplication1;

import System.*;
import System.Drawing.*;
import System.ComponentModel.*;
import System.Windows.Forms.*;

	...

        // Display a message box. The Help button opens the Mspaint.chm
        // Help file, and the "mspaint.chm::/paint_brush.htm" Help keyword
        // shows the associated topic.
        DialogResult r7 = MessageBox.Show("Message with Help file and keyword.",
            "Help Caption", MessageBoxButtons.OK, MessageBoxIcon.Question,
            MessageBoxDefaultButton.Button1, (MessageBoxOptions)0,
            "mspaint.chm", "mspaint.chm::/paint_brush.htm");

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft