How to show a message box in a .net c# or vb console application ? Something like:
Console.WriteLine("Hello World");
MessageBox.Show("Hello World");
or
Console.WriteLine("Hello")
MsgBox("Hello")
in c# and vb respectively.
Is it possible?
We can show a message box in a console application. But first include this reference in your vb.net or c# console application
Reference:
To add reference in vb.net program right click (in solution explorer) on your project name-> then add reference-> then .Net-> then select System.Windows.Forms.
To add reference in c# program right click in your project folders shown in solution explorer on add references-> .Net -> select System.Windows.Forms.
then you can do the below code for c# console application:
For the vb.net application you can simply code after inclusion of above mentioned reference
Adapted from this answer to a related question.
To have a simple message box inside your console application you can follow the below steps.
User the property to call the message box.
MessageBox((IntPtr)0, "asdasds", "My Message Box", 0);
In C# add the reference "PresentationFramework" in the project. Next in the class that you need the
MessageBox
addalso you can call the
MessageBox
class without the using like that: