Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
447 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...