2011-02-17 46 views

回答

1

給出這裏,您可以創建自定義對話框:

http://www.codeproject.com/KB/cs/A_Custom_Message_Box.aspx

+0

哎,你爲什麼要這樣一個可怕的期待消息框?你可以使用內置的。免費。你不必做更糟糕的工作來重塑你自己的事業。 – 2011-02-17 07:02:05

3

這裏有一個built-in method。它將自動在您的指定參數屏幕上顯示一個消息框。例如,下面的代碼行:

MessageBox.Show("Your body text goes here.", 
       "Message Title", 
       MessageBoxButtons.YesNo); 

會產生一個消息框,如下所示:

      sample message box


你也可以指定你的消息框圖標使用MessageBox.Show functiondifferent overload。例如:

MessageBox.Show("Your body text goes here.", 
       "Message Title", 
       MessageBoxButtons.YesNo, 
       MessageBoxIcon.Warning); 

圖標值的完整列表可用here


MessageBox.Show函數的返回值是對應於被點擊的消息框,該按鈕DialogResult value。通過檢查返回值,您可以確定用戶選擇了哪個操作過程。例如:

private void QueryExitApplication() 
{ 
    // Show a message box, asking the user to confirm that they want to quit 
    DialogResult result; 
    result = MessageBox.Show("Do you really want to quit this application?", 
          "Quit Application?", 
          MessageBoxButtons.YesNo, 
          MessageBoxIcon.Warning); 

    // Check the returned value of the MessageBox.Show function 
    // (this corresponds to the button clicked by the user) 
    if (result == DialogResult.Yes) 
    { 
     // Close the form 
     this.Close(); 
    } 

    // Otherwise, they selected No (so do nothing) 
} 
相關問題