Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Respond only after i click twice at the button(Dialog Box)

Status
Not open for further replies.

beginner81

Programmer
Oct 27, 2003
44
MY
I've created a dialogBox form with 2 button on it, "Yes", and "No". When the user click at button "Yes", message "You click Yes" will prompt out. And "you click No" message will prompt out if the users click at "No" button. Here r the source code.

DialogConfirmation confirm = new DialogConfirmation ();

if (confirm.ShowDialog() == DialogResult.Yes)
{
MessageBox("You Click Yes");
}

else if (confirm.ShowDialog() == DialogResult.No)
{
MessageBox("You Click NO");
}


The problem is i have to click the "No" button twice in order to prompt out the message "You click NO" .. As far as i know, the problem raised because I've make 2 evaluation here as : if (confirm.ShowDialog() == DialogResult.Yes) and if (confirm.ShowDialog() == DialogResult.No) ..
How am i goin to solve the problem ? i know it can be easily solve by the following code:

if (confirm.ShowDialog() == DialogResult.Yes)
{
MessageBox("You Click Yes");
}

else
{
MessageBox("You Click NO");
}

but what if i have 3 or more buttons in a dialog box ?
 
you use something like:

Code:
DialogResult dlgResult = confirm.ShowDialog();
then you do the evaluation:
Code:
if (dlgResult == DialogResult.Yes)
{
}
else if (dlgResult == ....

or you could use a switch
Code:
switch (dlgResult)
{
    case DialogResult.Yes : ....
                            break;
    case DialogResult.No  : .....
                            break;
    ..............................
    default : .....
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top