Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show message Box in .net console application

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?

like image 995
Syed Osama Maruf Avatar asked Mar 29 '15 05:03

Syed Osama Maruf


People also ask

How do I display message box?

To display a message box, call the static method MessageBox. Show. The title, message, buttons, and icons displayed in the message box are determined by parameters that you pass to this method.

Which method is used to display message on the screen in C#?

MessageBox is a class in C# and Show is a method that displays a message in a small window in the center of the Form. MessageBox is used to provide confirmations of a task being done or to provide warnings before a task is done. Create a Windows Forms app in Visual Studio and add a button on it.


1 Answers

We can show a message box in a console application. But first include this reference in your vb.net or c# console application

System.Windows.Forms; 

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:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; namespace ConsoleApplication6 {     class Program     {         static void Main(string[] args)         {               MessageBox.Show("Hello World");         }     } } 

For the vb.net application you can simply code after inclusion of above mentioned reference

Module Module1      Sub Main()         MsgBox("Hello")         Console.ReadKey()       End Sub  End Module 

Adapted from this answer to a related question.

like image 182
Syed Osama Maruf Avatar answered Sep 18 '22 08:09

Syed Osama Maruf