MessageBoxIcon 枚举

定义

指定要显示的信息的常量。

public enum class MessageBoxIcon
public enum MessageBoxIcon
type MessageBoxIcon = 
Public Enum MessageBoxIcon
继承
MessageBoxIcon

字段

名称 说明
None 0

消息框不包含任何符号。

Error 16

消息框包含一个符号,该符号由带红色背景的圆圈中的白色 X 组成。

Hand 16

消息框包含一个符号,该符号由带红色背景的圆圈中的白色 X 组成。

Stop 16

消息框包含一个符号,该符号由带红色背景的圆圈中的白色 X 组成。

Question 32

消息框包含由圆圈中的问号组成的符号。 不再建议使用问号消息图标,因为它不明确表示特定类型的消息,并且因为作为问题的邮件短语可能适用于任何消息类型。 此外,用户可以将问号符号与帮助信息符号混淆。 因此,请勿在消息框中使用此问号符号。 系统继续支持其包含,仅用于向后兼容性。

Exclamation 48

消息框包含一个符号,该符号由带有黄色背景的三角形中的感叹号组成。

Warning 48

消息框包含一个符号,该符号由带有黄色背景的三角形中的感叹号组成。

Asterisk 64

消息框包含一个符号,该符号由圆圈中的小写字母 i 组成。

Information 64

消息框包含一个符号,该符号由圆圈中的小写字母 i 组成。

示例

下面的代码示例演示如何使用 a MessageBox 来通知用户缺少的 TextBox条目。 此示例要求从具有 a ButtonTextBox on 的现有窗体调用该方法。

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    const string message =
        "Are you sure that you would like to close the form?";
    const string caption = "Form Closing";
    var result = MessageBox.Show(message, caption,
                                 MessageBoxButtons.YesNo,
                                 MessageBoxIcon.Exclamation);

    // If the no button was pressed ...
    if (result == DialogResult.No)
    {
        // cancel the closure of the form.
        e.Cancel = true;
    }
}
Private Sub Form1_FormClosing( _
    ByVal sender As System.Object, _
    ByVal e As System.Windows.Forms.FormClosingEventArgs) _
    Handles MyBase.FormClosing

    Dim message As String = _
            "Are you sure that you would like to close the form?"
    Dim caption As String = "Form Closing"
    Dim result = MessageBox.Show(message, caption, _
                                 MessageBoxButtons.YesNo, _
                                 MessageBoxIcon.Exclamation)

    ' If the no button was pressed ...
    If (result = DialogResult.No) Then
        ' cancel the closure of the form.
        e.Cancel = True
    End If
End Sub

注解

此枚举由 MessageBox 类使用。 此枚举的每个成员的说明都包含符号的典型表示形式。 显示的实际图形是操作系统常量的功能。 在当前实现中,有四个唯一符号,其中分配了多个值。

下表显示了不同的消息框图标。

图标 名称
红色圆圈中的白色
蓝色圆圈中的白色问号蓝色 Question
黄色三角形中的黑色 惊叹号
蓝色圆圈中的白色小写 i 星号
红色圆圈中的白色 停下
红色圆圈中的白色 Error
黄色三角形中的黑色 Warning
蓝色圆圈中的白色小写 i 信息

适用于