【问题标题】:How to show a custom error or warning message box in .NET Winforms?如何在 .NET Winforms 中显示自定义错误或警告消息框?
【发布时间】:2011-01-07 17:49:17
【问题描述】:

如何显示带有“叮!”的消息框声音和一个红色的“关闭”按钮?这就是我要说的:

我正在尝试创建一些自定义错误和警告,但是:

MessageBox.Show("asdf");

似乎没有给我任何自定义选项。

【问题讨论】:

    标签: c# .net winforms


    【解决方案1】:

    试试这个:

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

    【讨论】:

    • MSDN:您可以使用的其他图标:msdn.microsoft.com/en-us/library/…
    • 现在不支持 MessageBoxIcon.Error。尝试类似 MessageBox.Show("Some text", "Some title", MessageBoxButton.OK,MessageBoxImage.Warning);
    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:
      MessageBox.Show(
        "your message",
        "window title", 
        MessageBoxButtons.OK, 
        MessageBoxIcon.Asterisk //For Info Asterisk
        MessageBoxIcon.Exclamation //For triangle Warning 
      )
      

      【讨论】:

        【解决方案4】:

        如果你不使用命名空间,你应该添加它:

        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);
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-08-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多