How do I make a box prompting the user to answer "yes" or "no" to a question, and how would I handle which result is returned?
Cheers. :)
Printable View
How do I make a box prompting the user to answer "yes" or "no" to a question, and how would I handle which result is returned?
Cheers. :)
VB Code:
If MessageBox.Show("Text", "Caption", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then '...said yes Else '...said no End If
Solved. :)
Many ways. Here's a quickie:
VB Code:
Dim response as DialogResult response = MessageBox.Show("Your message","Your Title", MessageBoxButtons.YesNo) If response = DialogResult.Yes Then 'Do somthing End If
It may not be the case here, but many people misuse the Yes/No button combination. In the vast majority of cases you should use OK/Cancel. Here are examples of the proper use of the two.
If the user clicked an Exit button and you displayed a message box asking "Are you sure you want to exit?", the correct buttons to display would be OK and Cancel. OK means "go ahead and do what I asked for" and Cancel means "don't do what I asked for".
If the user clicked an Exit button and you displayed a message box asking "Do you want to save before exiting?", the correct buttons to display would be Yes and No. Yes means "go ahead and do what I asked for and perform the extra action" and No means "go ahead and do what I asked for but don't perform the extra action". You could also choose to display Yes, No and Cancel, where Yes and No mean the same as above and Cancel means "don't do what I asked for" again.
There are obviously other situations where Yes and No are appropriate like, if you were to ask "Do you live in the United States?", but when it comes to confirming requested actions, OK and Cancel are more generally the correct choice. In general:
OK means perform the requested action;
Yes means perform the requested action plus an additional action;
No means perform the requested action but not an additional action;
Cancel means perform no action.