tags:

views:

12378

answers:

4

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.

+7  A: 
using System.Windows.Forms;

...

MessageBox.Show( "hello world" );
moobaa
+7  A: 

It is a static function on the MessageBox class, the simple way to do this is using

MessageBox.Show("my message");

in the System.Windows.Forms class. You can find more on the msdn page for this here . Among other things you can control the message box text, title, default button, and icons. Since you didn't specify, if you are trying to do this in a webpage you should look at triggering the javascript alert("my message"); or confirm("my question"); functions.

George Mauer
+18  A: 

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", DialogBoxButtons.YesNo) == DialogResult.Yes) {
     //some interesting behaviour here
}

which I guess is a bit unwieldy but it gets the job done.

Merus
A: 

how to retrieve sqlserver data message in c#

chaluka Rathnayaka
This site doesn't work that way. Create your own question to get answers. It's "normal" forum.
MadBoy
This is nothing to do with the topic. If you want to ask a question, post a new question.
Tom W