Reputation: 225
If a user checks the Checkbox
, how do I code to show MessageBox.Show("..."
, with YesNoCancel
buttons in the message box, and when a user clicks no, another MessageBox.Show
pops up?
My code is this so far and it will not work:
private void lipsCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (lipsCheckBox.Checked = MessageBox.Show("...?",
"Want something else?",
MessageBoxButtons.YesNoCancel, MessageBox.Show("...?",
"Yea, Burt's bees?",
MessageBoxButtons.YesNoCancel, MessageBox.Show("...??",
"Hell yea LipxMedx?",
MessageBoxButtons.YesNoCancel),
MessageBoxIcon.Question);
}
Upvotes: 2
Views: 92494
Reputation: 7092
You must know about the MessageBox Dialog
if (checkBox1.Checked && (MessageBox.Show("Yes or no", "The Title",
MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes))
{
//TODO: Stuff
}
Upvotes: 19
Reputation: 2962
You can do it as follows:
private void lipsCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (lipsCheckBox.Checked)
{
DialogResult dr = MessageBox.Show("...?", "Want something else?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
if(dr == DialogResult.Yes)
{
//
}
else if(dr == DialogResult.Cancel)
{
//
}
}
}
Upvotes: 6
Reputation: 561
Do something like this:
if (checkBox1.Checked)
{
DialogResult dr = MessageBox.Show("Message.", "Title", MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
// Do something
}
}
You should be able to use this snippet to do the rest of what you need.
Upvotes: 12