Reputation: 285
I'm having trouble making a dialog with MessageBox with a text like "Do you want to save chanes to Untitled?" with 3 buttons like "save","don't save" and "cancel" ?
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
}
i tried this but its not working
Upvotes: 0
Views: 1044
Reputation: 26209
your Question is not clear, if you want to display a MessageBox
Try this:
DialogResult result3 = MessageBox.Show("Do you want to save changes to Untitled?",
"The Question",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question);
//While handling The Result
if (result3 == DialogResult.Yes)
{
//statements if Result = Yes
}
else if (result3 == DialogResult.No)
{
//statements if Result = NO
}
Solution:
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
if you want to create a MessageBox
with your own Buttons , then you have to design one.
Upvotes: 0
Reputation:
Use this sample:
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);
Upvotes: 1