Click here to Skip to main content
15,911,142 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
pls how can i check for the condition (No and Cancel) if i'm using
if (MessageBox.Show("Save Analysis and/or Design", "Save", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning) == DialogResult.Yes)
format of messageBox thanks.
Posted

I think S. Magus gives a correct and solid answer above.

I would only use this alternative style of coding in a situation where there were several possible results to be examined/acted upon:
C#
switch(MessageBox.Show("Save Analysis and/or Design", "Save", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning))
{
    case DialogResult.Yes:
        // call 'Yes function
        break;
    case DialogResult.No:
        // call 'No function
        break;
    case DialogResult.Retry:
        // call 'Retry
        break;
    case DialogResult.Cancel:
        // call 'Cancel function
        break;
    default:
        break;
}

The above 'takes advantage' of the fact that DialogResult is an Enumeration, and, thus, can be used as the selector in a switch/case statement.
 
Share this answer
 
C#
DialogResult result = MessageBox.Show("Save Analysis and/or Design", "Save", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);

if (result == DialogResult.Yes)
    Yes();
else if (result == DialogResult.No)
    No();
else 
    Cancel();
 
Share this answer
 
Comments
BillWoodruff 23-Sep-11 5:15am    
Excellent answer. +5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900