当我点击一个按钮时,我想在屏幕上弹出一个框并显示一条简单的信息。没什么好看的。我该怎么做?

有帮助吗?

解决方案

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

确保 System.Windows.Forms 程序集引用了您的项目。

其他提示

只需输入 mbox 然后按Tab键,它将为您提供一个提示消息框的神奇快捷方式。

在Visual Studio 2015(社区版)中, System.Windows.Forms 不可用,因此我们无法使用 MessageBox.Show(" text")

使用此代替:

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

注意:您的函数必须定义为异步才能在 await Msg.ShowAsync()之上使用。

试试这个:

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

没什么特别的?试试MessageBox

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

为什么不使用工具提示?

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

上面的代码将显示您点击的1000毫秒(1秒)的消息。

要进行呼叫,您可以在按钮点击事件中使用以下内容:

ShowToolTip("Hello World");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top