user2085275
user2085275

Reputation: 225

Confirmation Message

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

Answers (3)

spajce
spajce

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

Igoy
Igoy

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

saegeoff
saegeoff

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

Related Questions