我該怎麼說,如果按鈕上的按鈕是按下了這個,那和另一個?在C#中。MessageBox按鈕?
23
A
回答
55
您對
MessageBox.Show
需要調用傳遞MessageBoxButtons.YesNo
得到是/沒有按鈕,而不是在OK按鈕。該呼叫(這將阻止執行,直到對話框返回)的結果進行比較,以
DialogResult.Yes
....
if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
// user clicked yes
}
else
{
// user clicked no
}
6
8
如果你真的希望是和否按鈕(並假設的WinForms):
void button_Click(object sender, EventArgs e)
{
var message = "Yes or No?";
var title = "Hey!";
var result = MessageBox.Show(
message, // the message to show
title, // the title for the dialog box
MessageBoxButtons.YesNo, // show two buttons: Yes and No
MessageBoxIcon.Question); // show a question mark icon
// the following can be handled as if/else statements as well
switch (result)
{
case DialogResult.Yes: // Yes button pressed
MessageBox.Show("You pressed Yes!");
break;
case DialogResult.No: // No button pressed
MessageBox.Show("You pressed No!");
break;
default: // Neither Yes nor No pressed (just in case)
MessageBox.Show("What did you press?");
break;
}
}
0
檢查:
if (
MessageBox.Show(@"Are you Alright?", @"My Message Box",MessageBoxButtons.YesNo) == DialogResult.Yes)
{
//YES ---> Ok IM ALRIGHHT
}
else
{
//NO --->NO IM STUCK
}
問候
2
爲.NET 4.5的正確答案的更新版本會。
if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxImage.Question)
== MessageBoxResult.Yes)
{
// If yes
}
else
{
// If no
}
此外,如果您想要將按鈕綁定到視圖模型中的命令,可以使用以下命令。這與MvvmLite兼容:
public RelayCommand ShowPopUpCommand
{
get
{
return _showPopUpCommand ??
(_showPopUpCommand = new RelayCommand(
() =>
{
// Put if statement here
}
}));
}
}
0
這種方式可以在MessageBox窗口中按'YES'或'NO'按鈕的同時檢查條件。
DialogResult d = MessageBox.Show("Are you sure ?", "Remove Panel", MessageBoxButtons.YesNo);
if (d == DialogResult.Yes)
{
//Contents
}
else if (d == DialogResult.No)
{
//Contents
}
相關問題
- 1. MessageBox按鈕 - 設置語言?
- 2. 如何刪除MessageBox按鈕?
- 3. GXT MessageBox - 自定義按鈕
- 4. C#MessageBox的按鈕和UI
- 5. 以編程方式單擊MessageBox按鈕
- 6. 如何本地化Metro MessageBox按鈕
- 7. WPFToolkit MessageBox的按鈕只有英文版
- 8. nsis - 定製MessageBox上的按鈕文本
- 9. 更改MessageBox按鈕文本的語言
- 10. 如何獲取MessageBox按鈕標題?
- 11. vb.net messagebox yes.no按鈕有其他文本?
- 12. MessageBox自動繼續而不按下按鈕
- 13. PyQt - 單擊「退出」按鈕時顯示MessageBox
- 14. 在InstallShield的MessageBox中更改OK按鈕的語言環境
- 15. 如何禁用並啓用MessageBox中的重試按鈕?
- 16. 在MessageBox問題上實現重試按鈕功能(C#)
- 17. 如何在MessageBox上顯示3個按鈕?
- 18. Java從main和另一個單選按鈕中打印messageBox
- 19. MessageBox - 兩個按鈕做同樣的事情?
- 20. 添加按鈕以複製MessageBox中的文本
- 21. MessageBox展開按鈕以獲取更多錯誤說明
- 22. 如何在Windows Phone的Messagebox中添加超鏈接按鈕?
- 23. 使用MessageBox清除文本框是按鈕
- 24. 需要在Extjs MessageBox中的按鈕上設置類/標識值
- 25. 用「自定義按鈕」創建MessageBox的簡單方法
- 26. 我有一個問題,與我的單選按鈕messagebox vb.net
- 27. 在winforms的MessageBox中居中確定按鈕
- 28. 有一個MessageBox確認工作作爲一個提交按鈕
- 29. WPF MessageBox按鈕不是操作系統主題
- 30. 如何檢測Windows窗體MessageBox中的幫助按鈕?
@xxMUROxx請不要編輯重構代碼的答案。如果您覺得需要添加改進的其他內容,請發表評論或添加您自己的答案。 – 2015-05-11 13:15:50