Syed Osama Maruf Syed Osama Maruf - 1 year ago 89 Question

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");



in c# and vb respectively.

Is it possible?

Answer Source

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


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 application you can simply code after inclusion of above mentioned reference

Module Module1

    Sub Main()

    End Sub

End Module


To add reference in 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.

Adapted from this answer to a related question.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download