3
Answers

how to Use Message Box in C#? Like in VB.

Photo of Raghu Janardhan

Raghu Janardhan

12y
13.9k
1

How to use Message Box in C#

Answers (3)

1
Photo of Vulpes
NA 96k 2.6m 12y
Just as a matter of interest it's possible to use VB.Net's MsgBox function from C# as the following example shows:

/* add a reference to Microsoft.VisualBasic.dll to your project */

using System;
using Microsoft.VisualBasic;

class Test
{
    static void Main()
    {
        string msg = "Do you want to use VB's MsgBox from C#?";
        MsgBoxStyle style = MsgBoxStyle.YesNo;
        string title = "Choose option";
        MsgBoxResult result = Interaction.MsgBox(msg, style, title);               

        if (result == MsgBoxResult.Yes)
        {
           Console.WriteLine("OK, you're using it!");
        }
        else
        {
           Console.WriteLine("Then use System.Windows.Forms.MessageBox.Show instead.");
        }  

        Console.ReadKey();
    }
}

However, there's little point in doing so unless you're also using another VB.Net function such as InputBox which doesn't have a convenient alternative in the System.Windows.Forms namespace.


0
Photo of Prasant Jinaga
946 751 430.4k 12y
Hi Raghu,

following is the syntax to use message box in C#

messagebox.show();

in VB

MsgBox("Welcome to Microsoft Visual Basic")

Thanks,
Prasant
0
Photo of Satyapriya Nayak
NA 39.3k 13.3m 12y
Hi Raghu,

Please refer the below links

http://www.dotnetperls.com/messagebox-show

http://msdn.microsoft.com/en-us/library/system.windows.forms.messagebox%28v=vs.71%29.aspx

Thanks
If this post helps you mark it as answer