Home > DeveloperSection > Forums > How do I create a MessageBox in C#?
Ashish Pandey

Total Post:128

Points:898
Posted on    September-23-2013 3:53 AM

 WPF
Ratings:


 1 Reply(s)
 666  View(s)
Rate this:

I have just installed C# for the first time, and at first glance it appears to be very similar to VB6. I decided to start off by trying to make a 'Hello, World!' UI Edition.

I started in the Form Designer and made a button named "Click Me!" proceeded to double-click it and typed in

MessageBox("Hello, World!");

I received the following error:

MessageBox is a 'type' but used as a 'variable'

Fair enough, it seems in C# MessageBox is an Object. I tried the following

MessageBox a = new MessageBox("Hello, World!");

I received the following error: MessageBox does not contain a constructor that takes '1' arguments

Now I am stumped. Please help.



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    September-23-2013 6:51 AM

Hi Ashish,

MessageBox.Show also returns a DialogResult, which if you put some buttons on there, means you can have it returned what the user clicked. Most of the time I write something like

if (MessageBox.Show("Do you want to continue?", "Question", MessageBoxButton.YesNo) == MessageBoxResult.Yes) {

     //some interesting behaviour here

}


Don't want to miss updates? Please click the below button!

Follow MindStick