I had a very perplexing problem that took a while to figure out, so I thought I would pass it on. I had 2 communications programs, the original Host and a Client that was copied from the original and modified. There was an identical multiline textbox on each form. The user had the option of typing in the textbox and clicking the Send button, or simply hitting the Enter key. The Enter keystroke was supposed to be intercepted in the KeyPress event and call the Send button Click routine. It worked great on the copied and modified program, but not on the original program. A debug statement placed in the KeyPress routine showed that the Enter keystroke was never being processed. So I loaded each form into a NotePad window and compared them side by side. The only non-code difference I could find was that a different Command button was identified as "Default" on the faulty form (a Command button that I had yet to program). Changing this corrected the problem.
A subsequent investigation revealed "If the command button is the default command button for the form, pressing ENTER chooses the button, even if you change the focus to a different control other than a command button." I have no idea how it got set on just the one form, but it appears that if a "Default" Command button is identified, the Enter key is processed in the "Default" button instead of the control with the current focus.
J.A. Coutts
A subsequent investigation revealed "If the command button is the default command button for the form, pressing ENTER chooses the button, even if you change the focus to a different control other than a command button." I have no idea how it got set on just the one form, but it appears that if a "Default" Command button is identified, the Enter key is processed in the "Default" button instead of the control with the current focus.
J.A. Coutts