Link to home
Start Free TrialLog in
Avatar of Karl66
Karl66

asked on

C# using Message.box == DialogResult.Yes and handling the button selection

C# VS 2008/2005 - Dianlogue box button selection. Simple.

I have a YES or NO Dialogue box and when the users selects YES or NO they get another dialogue box informing them of their selection. Simple yea? Mine is not working it lets me click the main message box YES or NO twice and then gives me a YES possibly NO. Looked so straight forward.

Thoughts?

        private void btnDisplayMessageBox_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Select yes or No.", "Yes or No", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

            if (MessageBox.Show("Select yes or No.", "Yes or No", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes);
            {
                MessageBox.Show("You chose Yes.");
                // I tried break, return and this.Close() here but I do not like the results.
            }
            if (MessageBox.Show("Select yes or No.", "Yes or No", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No);
            {
                MessageBox.Show("You chose No.");
                // I tried break, return and this.Close() here but I do not like the results.
            }
        }
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial