.NET: How to have Escape close a MessageBox.Show()

dialogmodal-dialognetwinforms

Assuming the code:

MessageBox.Show(this, 
       "Would you like the differential girdle spring on the up-end of the grammeters?", 
       "Smi-Boloid Stater Slots", 
       MessageBoxButtons.YesNo, 
       MessageBoxIcon.Warning);

alt text

If the user presses Escape, i want it to close the message box, and the Show() method can return DialogResult.None.

Related question: How can i enable the "X" in the upper-right of a MessageBox.Show to let the user abort?


Kind of like how a Windows Explorer confirmation dialog lets you press escape to abort.

Kind of like how an Internet Explorer confirmation dialog lets you press escape to abort.

Kind of like how an Outlook confirmation dialog lets you press escape to abort.

Kind of like how every dialog in the history of the universe lets the user press escape ,or click X, in order to say:

"I have no earthly idea what you're
asking me, please just don't break my
computer."


From the Vista UX Guidelines

Use Yes and No buttons only to respond to yes or no questions. The
main instruction should be naturally
expressed as a yes or no question.
Never use OK and Cancel for yes or no
questions.

Best Answer

You have to enable the "Cancel" option with the enum value "MessageBoxButtons.YesNoCancel"

This will return DialogResult.Cancel

enter image description here