Επεξεργασία

Κοινή χρήση μέσω


MessageBoxIcon Enum

Definition

Specifies constants defining which information to display.

public enum class MessageBoxIcon
public enum MessageBoxIcon
type MessageBoxIcon = 
Public Enum MessageBoxIcon
Inheritance
MessageBoxIcon

Fields

Name Value Description
None 0

The message box contains no symbols.

Error 16

The message box contains a symbol consisting of white X in a circle with a red background.

Hand 16

The message box contains a symbol consisting of a white X in a circle with a red background.

Stop 16

The message box contains a symbol consisting of white X in a circle with a red background.

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.

Exclamation 48

The message box contains a symbol consisting of an exclamation point in a triangle with a yellow background.

Warning 48

The message box contains a symbol consisting of an exclamation point in a triangle with a yellow background.

Asterisk 64

The message box contains a symbol consisting of a lowercase letter i in a circle.

Information 64

The message box contains a symbol consisting of a lowercase letter i in a circle.

Examples

The following code example shows how to use a MessageBox to inform the user of a missing entry in a 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  

Remarks

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 Name
White X in red circle Hand
White question mark in blue circle Question
Black exclamation point in yellow triangle Exclamation
White lowercase i in blue circle Asterisk
White X in red circle Stop
White X in red circle Error
Black exclamation point in yellow triangle Warning
White lowercase i in blue circle Information

Applies to