2009-11-27 111 views

回答

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

確保System.Windows.Forms組件被引用到您的項目中。

+1

不要忘記分號:) – anon58192932 2012-10-09 19:48:52

+7

要在VS中添加對程序集的引用,請右鍵單擊您的項目,然後單擊'添加引用...'。然後你可以搜索'System.Windows.Forms'。 – GabLeRoux 2013-12-17 20:29:12

30

只需鍵入mbox然後單擊標籤,它會給你一個神奇捷徑打氣一個消息框。

+3

這是美妙的 – anon58192932 2012-11-15 21:53:27

+2

花花公子。非常好! – austin 2013-03-09 04:47:59

2

試試這個:

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

在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()

+0

我想你正在UWP或WinRT下進行檢查。 'System.Windows.Forms'應該仍然可用,我相當確定。 – nawfal 2016-10-17 13:30:56

0

爲什麼不使用工具提示?

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"); 
相關問題