Dialog box exit
-
I have a modal dialog box with AcceptButton & CancelButton Is there a way to test if the dialog was closed with the user pressing 'Enter' as apposed to using the mouse to click either of the buttons or the control box? MyDialog dlg = new MyDialog(); DialogResult rc = dlg.ShowDialog(); if(dlg.wasEnterPressed()) ... The 'Click' event on the AcceptButton fires for both mouse & keypress. I tried to look at the KeyDown event but that doesn't fire when 'Enter' is pressed.
-
I have a modal dialog box with AcceptButton & CancelButton Is there a way to test if the dialog was closed with the user pressing 'Enter' as apposed to using the mouse to click either of the buttons or the control box? MyDialog dlg = new MyDialog(); DialogResult rc = dlg.ShowDialog(); if(dlg.wasEnterPressed()) ... The 'Click' event on the AcceptButton fires for both mouse & keypress. I tried to look at the KeyDown event but that doesn't fire when 'Enter' is pressed.
As you have an AcceptButton, it appears that the Click event of the OK button precedes the KeyDown event for the Enter key and kills the dialog box before the KeyDown event fires. Try NOT declaring the AcceptButton and then see whether the KeyDown event fires for the Enter key. Regards, Ashok Dhamija _____________________________ Padam Technologies
-
As you have an AcceptButton, it appears that the Click event of the OK button precedes the KeyDown event for the Enter key and kills the dialog box before the KeyDown event fires. Try NOT declaring the AcceptButton and then see whether the KeyDown event fires for the Enter key. Regards, Ashok Dhamija _____________________________ Padam Technologies