MessageBoxIcon 列舉

定義

指定常數,定義要顯示的資訊。

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

欄位

Asterisk 64

訊息方塊包含的符號是圓形中有一個小寫字母 i。

Error 16

訊息方塊包含的符號是紅底圓形中有一個白色 X。

Exclamation 48

訊息方塊包含的符號是黃底三角形中有一個驚嘆號。

Hand 16

訊息方塊包含的符號是紅底圓形中有一個白色 X。

Information 64

訊息方塊包含的符號是圓形中有一個小寫字母 i。

None 0

訊息方塊未包含任何符號。

Question 32

訊息方塊包含的符號是圓形中有一個問號。 因為問號訊息圖示未清楚表示特定類型的訊息,而且問題訊息的措辭適用於各種訊息類型,所以已不再建議使用該圖示。 此外,使用者可能會混淆問號符號與說明資訊符號。 因此,請勿在訊息方塊中使用這個問號符號。 系統繼續支援將其納入,只為回溯相容性之用。

Stop 16

訊息方塊包含的符號是紅底圓形中有一個白色 X。

Warning 48

訊息方塊包含的符號是黃底三角形中有一個驚嘆號。

範例

下列程式碼範例示範如何使用 MessageBox ,通知使用者在 中 TextBox 遺漏的專案。 這個範例會要求從具有 和 TextBox 其上的現有表單 Button 呼叫 方法。

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 類別使用。 這個列舉的每個成員描述都包含符號的一般標記法。 顯示的實際圖形是作業系統常數的函式。 在目前的實作中,有四個唯一的符號,其中指派了多個值。

下表顯示不同的訊息方塊圖示。

圖示 名稱
紅色圓形的白色 X
藍色圓圈中的白色問號 問題
黃色三角形中的黑色驚嘆號 驚嘆號
藍色圓圈中的白色小寫 i 星號
紅色圓形的白色 X Stop
紅色圓形的白色 X 錯誤
黃色三角形中的黑色驚嘆號 警告
藍色圓圈中的白色小寫 i 資訊

適用於