neuromancer
neuromancer

Reputation: 55479

How to make a simple popup box in Visual C#?

When I click a button, I want a box to popup on the screen and display a simple message. Nothing fancy really. How would I do that?

Upvotes: 56

Views: 343853

Answers (6)

RooiWillie
RooiWillie

Reputation: 2228

Why not make use of a tooltip?

private void ShowToolTip(object sender, string message)
{
  new ToolTip().Show(message, this, Cursor.Position.X - this.Location.X, Cursor.Position.Y - this.Location.Y, 1000);
}

The code above will show message for 1000 milliseconds (1 second) where you clicked.

To call it, you can use the following in your button click event:

ShowToolTip("Hello World");

Upvotes: 1

shubz
shubz

Reputation: 133

In Visual Studio 2015 (community edition), System.Windows.Forms is not available and hence we can't use MessageBox.Show("text").

Use this Instead:

var Msg = new MessageDialog("Some String here", "Title of Message Box");    
await Msg.ShowAsync();

Note: Your function must be defined async to use above await Msg.ShowAsync().

Upvotes: 5

user6436606
user6436606

Reputation: 67

Try this:

string text = "My text that I want to display";
MessageBox.Show(text);

Upvotes: 3

Alex J
Alex J

Reputation: 10205

System.Windows.Forms.MessageBox.Show("My message here");

Make sure the System.Windows.Forms assembly is referenced your project.

Upvotes: 109

Spence
Spence

Reputation: 29322

Just type mbox then hit tab it will give you a magic shortcut to pump up a message box.

Upvotes: 40

Andrei Drynov
Andrei Drynov

Reputation: 8592

Nothing fancy? Try MessageBox

http://www.homeandlearn.co.uk/csharp/csharp_s1p9.html

Upvotes: 2

Related Questions