How to use the Enter key as Tab in a Windows Forms application

0 Likes
over 7 years ago

Problem:

Customer has a Windows Forms application that uses a form with a number of TextBox controls on it.
When they press "tab" or click the mouse on another control, the data is processed. When they press "enter" nothing happens. Customer asks: How can I have the enter key behave like the tab key?

Resolution:

In the properties for the form set the KeyPreview property to true.

Create a KeyDown event handler for the form and place the following code into it:

method-id Form1_KeyDown final private.
procedure division using by value sender as object e as type System.Windows.Forms.KeyEventArgs.
           
      if e::KeyCode = type System.Windows.Forms.Keys::Return
         set e::Handled to true
         set e::SuppressKeyPress to true
         invoke type SendKeys::Send("{TAB}")   
      end-if.
           
end method.
Comment List
Anonymous
Related Discussions
Recommended