【问题标题】:Show a message box from a class in c#?在c#中显示一个类的消息框?
【发布时间】:2009-04-03 18:59:40
【问题描述】:

如何让类与表单交互以显示消息框?

【问题讨论】:

  • 这通常不是一个好主意。理想情况下,该类应该将数据发送回表单并让表单显示消息框。如果您将 UI 细节编码到您的类中,那么它完全与该 UI 相关联。此外,它使单元测试变得不可能。

标签: c# class messagebox


【解决方案1】:
using System.Windows.Forms;
...
MessageBox.Show("Hello World!");

【讨论】:

    【解决方案2】:
    System.Windows.MessageBox.Show("Hello world"); //WPF
    System.Windows.Forms.MessageBox.Show("Hello world"); //WinForms
    

    【讨论】:

      【解决方案3】:

      试试这个:

      System.Windows.Forms.MessageBox.Show("Here's a message!");
      

      【讨论】:

        【解决方案4】:
        using System.Windows.Forms;
        
        public class message
        {
            static void Main()
            {  
                MessageBox.Show("Hello World!"); 
            }
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-08-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-10-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多