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?
This question is related to
c#
visual-studio
user-interface
popup
System.Windows.Forms.MessageBox.Show("My message here");
Make sure the System.Windows.Forms
assembly is referenced your project.
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");
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()
.
Try this:
string text = "My text that I want to display";
MessageBox.Show(text);
Just type mbox
then hit tab it will give you a magic shortcut to pump up a message box.
Nothing fancy? Try MessageBox
Source: Stackoverflow.com