I work on a system where most data collection forms are derived from a base form.
Each form has an AcceptButton set, so that when the Enter key is pressed, the AcceptButton’s event it raised.
I want to be able to show a warning to the user asking if they are sure they want to save after pressing enter. If they select ‘yes’, the AcceptButton event will be raised, and if they select ‘no’, then nothing will happen.
Is this possible to do from the base class?
I’ve tried setting the AcceptButton to nothing in the base class in the ProcessCmdKey method if enter is pressed, but I don’t know how I can reset it again.
I work on a system where most data collection forms are derived from a
Share
I think you’re on the right track with overriding the
ProcessCmdKeymethod, but why set AcceptButton to nothing? An implementation like this should sufficeThis will prompt the user when enter is pressed, and if they respond with No, then
Trueis returned, indicating the key has been processed and no further processing will take place. This will prevent theButton.Clickevent from raising.