<p>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.</p>

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

<pre><code>MessageBox("Hello, World!");
</code></pre>

<p>I received the following error:</p>

<p>MessageBox is a 'type' but used as a 'variable'</p>

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

<pre><code>MessageBox a = new MessageBox("Hello, World!");
</code></pre>

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

<p>Now I am stumped. Please help.</p>

[{'answer_id': 49151, 'author': 'moobaa', 'author_id': 3569, 'author_profile': 'https://Stackoverflow.com/users/3569', 'pm_score': 5, 'selected': False, 'text': '<p>Code summary:</p>\n\n<pre><code>using System.Windows.Forms;\n\n...\n\nMessageBox.Show( "hello world" );\n</code></pre>\n\n<p>Also (<a href="https://stackoverflow.com/a/6639482/1582588">as per this other stack post</a>): In Visual Studio expand the project in Solution Tree, right click on References, Add Reference, Select <code>System.Windows.Forms</code> on Framework tab. This will get the MessageBox working in conjunction with the using System.Windows.Forms reference from above.</p>\n'}, {'answer_id': 49152, 'author': 'George Mauer', 'author_id': 5056, 'author_profile': 'https://Stackoverflow.com/users/5056', 'pm_score': 3, 'selected': False, 'text': '<p>It is a static function on the MessageBox class, the simple way to do this is using</p>\n\n<pre><code>MessageBox.Show("my message");\n</code></pre>\n\n<p>in the System.Windows.Forms class.  You can find  more on the msdn page for this <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.messagebox.show.aspx" rel="noreferrer">here</a> . 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.</p>\n'}, {'answer_id': 49153, 'author': 'Merus', 'author_id': 5133, 'author_profile': 'https://Stackoverflow.com/users/5133', 'pm_score': 7, 'selected': True, 'text': '<p>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</p>\n\n<pre><code>if (MessageBox.Show("Do you want to continue?", "Question", MessageBoxButtons.YesNo) == MessageBoxResult.Yes) {\n     //some interesting behaviour here\n}\n</code></pre>\n\n<p>which I guess is a bit unwieldy but it gets the job done.</p>\n\n<p>See <a href="https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.dialogresult" rel="noreferrer">https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.dialogresult</a> for additional enum options you can use here.</p>\n'}, {'answer_id': 10829863, 'author': 'William Fitzmaurice', 'author_id': 1427875, 'author_profile': 'https://Stackoverflow.com/users/1427875', 'pm_score': 0, 'selected': False, 'text': '<p>In the <code>System.Windows.Forms</code> class, you can find more on the <a href="http://www.msdn.com/" rel="nofollow">MSDN</a> 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 <code>alert("my message");</code> or <code>confirm("my question");</code> functions.</p>\n'}, {'answer_id': 18951433, 'author': 'user2680314', 'author_id': 2680314, 'author_profile': 'https://Stackoverflow.com/users/2680314', 'pm_score': 0, 'selected': False, 'text': '<p>This is some of the things you can put into a message box. Enjoy <br />\n<code>MessageBox.Show("Enter the text for the message box",<br />\n                      "Enter the name of the message box",<br />\n                      (Enter the button names e.g. MessageBoxButtons.YesNo),<br />\n                      (Enter the icon e.g. MessageBoxIcon.Question),<br />\n                  (Enter the default button e.g. MessageBoxDefaultButton.Button1)</code><br />\nMore information can be found <a href="http://msdn.microsoft.com/en-us/library/ww6cfk80.aspx?cs-save-lang=1&amp;cs-lang=csharp#code-snippet-1" rel="nofollow">here</a>  </p>\n'}, {'answer_id': 21935165, 'author': 'Sagar Dev Timilsina', 'author_id': 3335710, 'author_profile': 'https://Stackoverflow.com/users/3335710', 'pm_score': 3, 'selected': False, 'text': '<p>Try below code:</p>\n\n<pre><code>MessageBox.Show("Test Information Message", "Caption", MessageBoxButtons.OK, MessageBoxIcon.Information);\n</code></pre>\n'}, {'answer_id': 28933652, 'author': 'KeithJ', 'author_id': 3470547, 'author_profile': 'https://Stackoverflow.com/users/3470547', 'pm_score': 0, 'selected': False, 'text': '<p>I got the same error <strong>\'System.Windows.Forms.MessageBox\' is a \'type\' but is used like a \'variable\'</strong>, even if using:</p>\n\n<pre><code>MessageBox.Show("Hello, World!");\n</code></pre>\n\n<p>I guess my initial attempts with invalid syntax caused some kind of bug and I ended up fixing it by adding a space between "MessageBox.Show" and the brackets ():</p>\n\n<pre><code>MessageBox.Show ("Hello, World!");\n</code></pre>\n\n<p>Now using the original syntax without the extra space works again:</p>\n\n<pre><code>MessageBox.Show("Hello, World!");\n</code></pre>\n'}, {'answer_id': 50077660, 'author': 'MicroDOS', 'author_id': 9714192, 'author_profile': 'https://Stackoverflow.com/users/9714192', 'pm_score': 1, 'selected': False, 'text': '<p>Also you can use a <code>MessageBox</code> with <code>OKCancel</code> options, but it requires many codes.\nThe <code>if</code> block is for <code>OK</code>, the <code>else</code> block is for <code>Cancel</code>. Here is the code:</p>\n\n<pre><code>if (MessageBox.Show("Are you sure you want to do this?", "Question", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)\n{\n    MessageBox.Show("You pressed OK!");\n}\nelse\n{\n    MessageBox.Show("You pressed Cancel!");\n}\n</code></pre>\n\n<p>You can also use a <code>MessageBox</code> with <code>YesNo</code> options:</p>\n\n<pre><code>if (MessageBox.Show("Are you sure want to doing this?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)\n{\n    MessageBox.Show("You are pressed Yes!");\n}\nelse\n{\n    MessageBox.Show("You are pressed No!");\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/49147', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4960/']