MessageBox 类

定义

显示消息框。Displays a message box.

public ref class MessageBox sealed
public sealed class MessageBox
type MessageBox = class
Public NotInheritable Class MessageBox
继承
MessageBox

注解

消息框是向用户显示文本消息的预制模式对话框。A message box is a prefabricated modal dialog box that displays a text message to a user. 可以通过调用Show MessageBox类的静态方法来显示消息框。You show a message box by calling the static Show method of the MessageBox class. 显示的文本消息是传递给Show的字符串参数。The text message that is displayed is the string argument that you pass to Show. 使用Show方法的若干重载还可以提供标题栏标题。Several overloads of the Show method also enables you to provide a title bar caption.

若要允许用户关闭消息框, 请Show在标题栏中显示一个具有 "确定" 按钮和 "关闭" 按钮的消息框。To enable a user to close a message box, Show displays a message box that has an OK button and a Close button in the title bar.

你还可以使用消息框向用户提出问题。You can also use a message box to ask a user a question. 用户通过单击多个指定为使用MessageBoxButton枚举显示的按钮之一来回答。The user answers by clicking one of several buttons that you specify to display by using the MessageBoxButton enumeration. 可以将此枚举传递给Show方法的多个重载。You can pass this enumeration to several overloads of the Show method. MessageBoxButton枚举的默认值为OKThe default value of the MessageBoxButton enumeration is OK.

可以通过检查Show返回的值来确定用户单击的按钮。You can determine which button a user clicks by examining the value that Show returns. 返回值是一个MessageBoxResult枚举值, 其中每个值等于消息框可以显示的按钮之一。The return value is a value of the MessageBoxResult enumeration, where each value equates to one of the buttons that a message box can display. 消息框的默认值为, OK因为 "确定" 是默认消息框按钮。The default value for message box is OK because OK is the default message box button. 但是, Show方法的某些重载使你能够提供不同MessageBoxResult的默认值。However, some overloads of the Show method enable you to provide a different MessageBoxResult default value.

消息框可以传达信息, 并可以询问具有不同程度的问题的问题。Message boxes can communicate information and can ask questions that have varying degrees of importance. 消息框使用图标来指示重要性。Message boxes use icons to indicate importance. 例如, 图标可以指示消息是信息性消息、警告消息还是重要消息。For example, icons can indicate whether the message is informational, is a warning, or is important. MessageBoxImage枚举封装一组可能的消息框图标。The MessageBoxImage enumeration encapsulates the set of possible message box icons. 默认情况下, 消息框不显示图标。By default, a message box does not display an icon. 不过, 您可以将MessageBoxImage值传递到若干Show方法重载之一, 以指定消息框包含一个图标。However, you can pass a MessageBoxImage value to one of several Show method overloads in order to specify that the message box includes an icon.

消息框有时提供特殊功能, 如从右到左阅读。Message boxes sometimes provide special functionality, such as right-to-left reading. 您可以通过使用MessageBoxOptions Show方法的某些重载接受的一个或多个枚举值来自定义消息框的行为。You can customize the behavior of a message box by using one or more MessageBoxOptions enumeration values that are accepted by some overloads of the Show method.

消息框始终具有所有者窗口。Message boxes always have an owner window. 默认情况下, 消息框的所有者是在消息框打开时应用程序中当前处于活动状态的窗口。By default, the owner of a message box is the window that is currently active in an application at the time that a message box is opened. 但是, 可以使用多个Window Show重载之一来指定另一个所有者。However, you can specify another owner for the Window by using one of several Show overloads. 有关所有者窗口的详细信息, 请Window.Owner参阅。For more information about owner windows, see Window.Owner.

有关详细信息, 请参阅MessageBox 示例For more information, see MessageBox Sample.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
Show(String)

显示一个消息框,该消息框包含消息并返回结果。Displays a message box that has a message and that returns a result.

Show(String, String)

显示一个消息框,该消息框包含消息和标题栏标题,并且返回结果。Displays a message box that has a message and title bar caption; and that returns a result.

Show(String, String, MessageBoxButton)

显示一个消息框,该消息框包含消息、标题栏标题和按钮,并且返回结果。Displays a message box that has a message, title bar caption, and button; and that returns a result.

Show(String, String, MessageBoxButton, MessageBoxImage)

显示一个消息框,该消息框包含消息、标题栏标题、按钮和图标,并且返回结果。Displays a message box that has a message, title bar caption, button, and icon; and that returns a result.

Show(String, String, MessageBoxButton, MessageBoxImage, MessageBoxResult)

显示一个消息框,该消息框包含消息、标题栏标题、按钮和图标,并接受默认消息框结果和返回结果。Displays a message box that has a message, title bar caption, button, and icon; and that accepts a default message box result and returns a result.

Show(String, String, MessageBoxButton, MessageBoxImage, MessageBoxResult, MessageBoxOptions)

显示一个消息框,该消息框包含消息、标题栏标题、按钮和图标,并且接受默认消息框结果、遵从指定选项并返回结果。Displays a message box that has a message, title bar caption, button, and icon; and that accepts a default message box result, complies with the specified options, and returns a result.

Show(Window, String)

在指定窗口的前面显示消息框。Displays a message box in front of the specified window. 该消息框显示消息并返回结果。The message box displays a message and returns a result.

Show(Window, String, String)

在指定窗口的前面显示消息框。Displays a message box in front of the specified window. 该消息框显示消息和标题栏标题,并且返回结果。The message box displays a message and title bar caption; and it returns a result.

Show(Window, String, String, MessageBoxButton)

在指定窗口的前面显示消息框。Displays a message box in front of the specified window. 该消息框显示消息、标题栏标题和按钮,并且返回结果。The message box displays a message, title bar caption, and button; and it also returns a result.

Show(Window, String, String, MessageBoxButton, MessageBoxImage)

在指定窗口的前面显示消息框。Displays a message box in front of the specified window. 该消息框显示消息、标题栏标题、按钮和图标,并且返回结果。The message box displays a message, title bar caption, button, and icon; and it also returns a result.

Show(Window, String, String, MessageBoxButton, MessageBoxImage, MessageBoxResult)

在指定窗口的前面显示消息框。Displays a message box in front of the specified window. 该消息框显示消息、标题栏标题、按钮和图标,并接受默认消息框结果和返回结果。The message box displays a message, title bar caption, button, and icon; and accepts a default message box result and returns a result.

Show(Window, String, String, MessageBoxButton, MessageBoxImage, MessageBoxResult, MessageBoxOptions)

在指定窗口的前面显示消息框。Displays a message box in front of the specified window. 该消息框显示消息、标题栏标题、按钮和图标,并且接受默认消息框结果、遵从指定选项并返回结果。The message box displays a message, title bar caption, button, and icon; and accepts a default message box result, complies with the specified options, and returns a result.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅