My company has a large application written in VB6, and for historical reasons, the application is navigated with the Enter key instead of with the Tab key. I don't know VB6, but I know that they currently set the focus for each control in a big select statement in the Form's KeyUp event if it's an EnterKey. Now we are starting to convert to .NET, and have to keep things consistent so the users won't have to TAB on some forms and ENTER on others. I want to write ancestor forms that will automatically ENTER from field to field instead of tabbing. A coworker told me that the way it's done in VB6 is to process buttons not on the CLICK event but on the KEYUP event. I need to continue doing this so I won't have leftover KeyUp events to pass back to VB6 after my form is finished. The order of events for buttons is
- button_PreviewKeyDown
- button_Click (apparently replacing the KeyPress event)
- form_KeyUp
- button_KeyUp
I created forms as follows:
- On the ANCESTOR form's KeyUp event, checks to see if it's an enter key. If it is an enter key, and the active control is not a button, it moves to the next field in tab order. Otherwise it ignores the key and lets the control handle it. If it is a button, the ancestor doesn't presume to know where the button wants control to go, because it will depend on what the button wants to do when it is "clicked".
- On the CHILD form's buttons, the click event does nothing, and the processing is duplicated in the KeyUp event and the MouseClick event.
- The ANCESTOR form has a protected Boolean, EatKeyUp, that can be set to True by the CHILD. This is used when the child form needs to send a MessageBox, because if the user enters through the OK button on the MessageBox, there is still a leftover KeyUp event that will be consumed by the ancestor form.
Although klugey, this actually seems to work. What I want to know is, is there a better way? Perhaps some setting somewhere that I can tell my application "Enter through forms instead of tabbing"? Are the events that I'm using instead of the click events the best ones?