PDA

Click to See Complete Forum and Search --> : escape key for a dailog result


kumar_1981
Mar 7th, 2007, 02:30 AM
hi

i created a dialog result


DialogResult Result = new DialogResult();
Result = MessageBox.Show("Are you sure you want to show the screen?", "", MessageBoxButtons.YesNo);
if (Result == DialogResult.Yes)
{

form2 f2=new form2();
f2.show();
}
if (Result == DialogResult.No)
{

MessageBox.Show " you are in form1";
}



After getting confirmation message if i click escape button i should get the Result with "NO"

how to capture DialogResult keydown event


Regards
Vinay Kumar

jmcilhinney
Mar 7th, 2007, 03:52 AM
Firstly, DialogResult is an enumeration. You don't use constructors to create enumerated values. Change this:DialogResult Result = new DialogResult();to this:DialogResult Result;Secondly, you're using the wrong buttons on your MessageBox. When you are asking the user to confirm an action that they've already asked for you don't use YesNo but rather OKCancel.

Finally, only a Cancel button on a MessageBox gets clicked automatically when the user presses the Escape key. If your MessageBox is showing YesNo then the user has to click the No button themselves. Fortunately for you, you will be using OKCancel for the reason I specified above so the user can use the Escape key to click the Cancel button.

kumar_1981
Mar 7th, 2007, 05:30 AM
hi


Thanks for the reply. i resolved the issue.

thank u once again for helping me in resolving this issue