Show a message box from a class in c#?

2019-02-16 06:53发布

问题:

How do you get a class to interact with the form to show a message box?

回答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:

Try this:

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


回答4:

using System.Windows.Forms;

public class message
{
    static void Main()
    {  
        MessageBox.Show("Hello World!"); 
    }
}