[英]making a dialog with messagebox c#
我在使用MessageBox創建對話框時遇到麻煩,該對話框的文本為“您是否想將chanes保存為Untitled?”。 有3個按鈕,例如“保存”,“不保存”和“取消”?
private void MenuItemNew()
{
if (textBox.Text == "")
{
textBox.Text = String.Empty;
}
else
DialogResult result3 = MessageBox.Show("Do you want to save changes to Untitled?",
"The Question",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);
if (result3 == DialogResult.Yes)
{
//statements if Result = Yes
}
else if (result3 == DialogResult.No)
{
//statements if Result = NO
}
我嘗試了這個但是它不起作用
使用此示例 :
MessageBox.Show("Dot Net Perls is awesome.");
//
// Dialog box with text and a title. [2]
//
MessageBox.Show("Dot Net Perls is awesome.",
"Important Message");
//
// Dialog box with two buttons: yes and no. [3]
//
DialogResult result1 = MessageBox.Show("Is Dot Net Perls awesome?",
"Important Question",
MessageBoxButtons.YesNo);
//
// Dialog box with question icon. [4]
//
DialogResult result2 = MessageBox.Show("Is Dot Net Perls awesome?",
"Important Query",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question);
//
// Dialog box with question icon and default button. [5]
//
DialogResult result3 = MessageBox.Show("Is Visual Basic awesome?",
"The Question",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
如果您要顯示一個MessageBox
,您的問題尚不清楚
嘗試這個:
DialogResult result3 = MessageBox.Show("Do you want to save changes to Untitled?",
"The Question",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question);
//處理結果時
if (result3 == DialogResult.Yes)
{
//statements if Result = Yes
}
else if (result3 == DialogResult.No)
{
//statements if Result = NO
}
解:
private void MenuItemNew()
{
if (textBox.Text.ToString().Trim().Equals(""))
{
textBox.Text = String.Empty;
}
else
{
DialogResult result3 = MessageBox.Show("Do you want to save changes to Untitled?","The Question",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1);
if (result3 == DialogResult.Yes)
{
//statements if Result = Yes
}
else if (result3 == DialogResult.No)
{
//statements if Result = NO
}
}//end of else block
}//end of function
如果要使用自己的Button創建一個MessageBox
,則必須設計一個。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.