Skip to main content

I want to code so that the <Enter> key behaves like the <Tab Key> whilst on a Windows form in that pressing the <Enter> key will...

a) Validate the field I've just pressed the <Enter> key on...

b) If no error then move onto next field as designated by the TabIndex order...

c) If ERROR then remain on field for corrective action.

I've noticed on the Knowlege database the following suggestion of code to do this...

http://kb.microfocus.com/display/4/kb/article.aspx?aid=36145

however when I cut & paste the relevent lines of code into my own solution I get may errors relating to the words 'Keyboard', 'RoutedEvent' & 'InputManager'!

Can someone provide code to help me out here please?

 

I want to code so that the <Enter> key behaves like the <Tab Key> whilst on a Windows form in that pressing the <Enter> key will...

a) Validate the field I've just pressed the <Enter> key on...

b) If no error then move onto next field as designated by the TabIndex order...

c) If ERROR then remain on field for corrective action.

I've noticed on the Knowlege database the following suggestion of code to do this...

http://kb.microfocus.com/display/4/kb/article.aspx?aid=36145

however when I cut & paste the relevent lines of code into my own solution I get may errors relating to the words 'Keyboard', 'RoutedEvent' & 'InputManager'!

Can someone provide code to help me out here please?

 

Ok....solved this one....

For the form you want to track the <ENTER> key as <TAB> set the KEYPREVIEW property to TRUE (default is FALSE)

Generate a KEYDOWN method call for the form and inside that method put the following code...

           if NOT e::KeyCode = type "System.Windows.Forms.Keys"::Return
              exit method
           end-if.
          
           invoke type SendKeys::Send("{TAB}")
           set e::Handled to true.

This will force a TAB to the next logical field as per the sequence in the TABINDEX properties for the fields on form.

e.g if the object on form has a tabindex value of 3 then the instruction will be to send the cursor to the object whose tabindex property is 4.

Note that where the TABSTOP property on a object is FALSE then the object is ignored!

LEAVE methods, for objects to be validated, are handled correctly and validation is done to ensure that objects in error are kept in focus.

Example is...

       method-id textBox1_Leave final private.
       working-storage section.
       01  Num-Display-99v99           pic -(9)9.99.
       01  Num-Entered-99v99           pic s9(9)v99.
       procedure division using by value sender as object e as type System.EventArgs.
      
           move spaces to ErrorMessage::Text
          
           set NormalColor to type Color::Black
           set ErrorColor  to type Color::Red
      
           Set textBox1::ForeColor to NormalColor
           Try
             Set Num-Entered-99v99 to type Convert::ToDecimal(textBox1::Text)
           Catch
              Move "Error with Textbox 1 value" to ErrorMessage::Text
              set textBox1::ForeColor to ErrorColor
              invoke textBox1::Focus()
              exit method
           End-Try.
          
           move Num-Entered-99v99 to Num-Display-99v99.
           move Num-Display-99v99  to textBox1::Text
      
      
       end method.