如何显示错误& .NET中的警告消息框/如何自定义MessageBox

时间:2010-01-21 13:21:05

标签: c# .net winforms

使用C#.NET(Winforms)。

我想知道如何显示带有Ding!!声音的消息框&一个红色的十字标记。这就是我所说的:

screenshot

如何为我的软件做这些事情,包括自定义错误和自定义警告?

MessageBox.Show("asdf");

不给我自定义。

4 个答案:

答案 0 :(得分:199)

试试这个:

MessageBox.Show("Some text", "Some title", 
    MessageBoxButtons.OK, MessageBoxIcon.Error);

答案 1 :(得分:19)

尝试详情:使用任何选项..

    MessageBox.Show("your message",
    "window title", 
    MessageBoxButtons.OK, 
    MessageBoxIcon.Warning // for Warning  
    //MessageBoxIcon.Error // for Error 
    //MessageBoxIcon.Information  // for Information
    //MessageBoxIcon.Question // for Question
   );

答案 2 :(得分:3)

MessageBox.Show(
  "your message",
  "window title", 
  MessageBoxButtons.OK, 
  MessageBoxIcon.Asterisk //For Info Asterisk
  MessageBoxIcon.Exclamation //For triangle Warning 
)

答案 3 :(得分:0)

如果不使用名称空间,则应添加该名称空间:

System.Windows.Forms.MessageBox.Show("Some text", "Some title", 
    System.Windows.Forms.MessageBoxButtons.OK, 
    System.Windows.Forms.MessageBoxIcon.Error);

或者,您可以在文件的开头添加

using System.Windows.Forms

然后使用(如先前的回答所述):

MessageBox.Show("Some text", "Some title", 
    MessageBoxButtons.OK, MessageBoxIcon.Error);