MessageBoxIcon MessageBoxIcon MessageBoxIcon MessageBoxIcon Enum

定义

指定常数来定义要显示的信息。Specifies constants defining which information to display.

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

字段

Asterisk Asterisk Asterisk Asterisk 64

消息框包含一个符号,该符号在圆圈中包含小写字母 i。The message box contains a symbol consisting of a lowercase letter i in a circle.

Error Error Error Error 16

消息框包含一个符号,该符号包含一个红色背景圆圈,圆圈中为白色 X 符号。The message box contains a symbol consisting of white X in a circle with a red background.

Exclamation Exclamation Exclamation Exclamation 48

消息框包含一个符号,该符号包含一个黄色背景三角形,三角形中为感叹号。The message box contains a symbol consisting of an exclamation point in a triangle with a yellow background.

Hand Hand Hand Hand 16

消息框包含一个符号,该符号包含一个红色背景圆圈,圆圈中为白色 X 符号。The message box contains a symbol consisting of a white X in a circle with a red background.

Information Information Information Information 64

消息框包含一个符号,该符号在圆圈中包含小写字母 i。The message box contains a symbol consisting of a lowercase letter i in a circle.

None None None None 0

消息框未包含符号。The message box contains no symbols.

Question Question Question Question 32

消息框包含一个符号,该符号包含一个圆圈,圆圈中为问号。The message box contains a symbol consisting of a question mark in a circle. 不再建议使用问号消息图标,因为这种图标无法清楚地表示特定类型的消息,并且作为问题的消息表述可应用于任何消息类型。The question mark message icon is no longer recommended because it does not clearly represent a specific type of message and because the phrasing of a message as a question could apply to any message type. 此外,用户可能会将问号符号与帮助信息符合混淆。In addition, users can confuse the question mark symbol with a help information symbol. 因此,请不要在消息框中使用问号符号。Therefore, do not use this question mark symbol in your message boxes. 系统继续支持它包含的内容,只为满足反向兼容性。The system continues to support its inclusion only for backward compatibility.

Stop Stop Stop Stop 16

消息框包含一个符号,该符号包含一个红色背景圆圈,圆圈中为白色 X 符号。The message box contains a symbol consisting of white X in a circle with a red background.

Warning Warning Warning Warning 48

消息框包含一个符号,该符号包含一个黄色背景三角形,三角形中为感叹号。The message box contains a symbol consisting of an exclamation point in a triangle with a yellow background.

示例

下面的代码示例演示如何使用MessageBox以通知用户中缺少某一条目TextBoxThe following code example shows how to use a MessageBox to inform the user of a missing entry in a TextBox. 此示例需要的方法称为从与现有的表单Button和一个TextBox上它。This example requires that the method is called from an existing form with a Button and a TextBox on it.

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:  
   void Form1_FormClosing(Object^ sender, FormClosingEventArgs^ e)  
   {  
      // If the no button was pressed ...  
      if ((MessageBox::Show(  
         "Are you sure that you would like to close the form?",   
         "Form Closing", MessageBoxButtons::YesNo,   
         MessageBoxIcon::Exclamation) == 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 类使用。This enumeration is used by the MessageBox class. 此枚举的每个成员的说明包含符号的典型表示形式。The description of each member of this enumeration contains a typical representation of the symbol. 实际显示的图形是操作系统常量的函数。The actual graphic displayed is a function of the operating system constants. 在当前实现中有四个唯一符号与分配给它们的多个值。In current implementations there are four unique symbols with multiple values assigned to them.

下表显示不同的消息框图标。The following table shows the different message box icons.

图标Icon nameName
白色 X 的红色圆圈White X in red circle 手动Hand
蓝色圆圈中的白色问号White question mark in blue circle 问题Question
黑色感叹号的黄色三角形Black exclamation point in yellow triangle 感叹号Exclamation
白色小写 i 中的蓝色圆圈White lowercase i in blue circle 星号Asterisk
白色 X 的红色圆圈White X in red circle 停止Stop
白色 X 的红色圆圈White X in red circle ErrorError
黑色感叹号的黄色三角形Black exclamation point in yellow triangle 警告Warning
白色小写 i 中的蓝色圆圈White lowercase i in blue circle 信息Information

适用于