To move from one textbox field to another

I make my sample form with textboxes on it, and buttons as a control to add, edit, save, undo, delete & close form, just to study the behavior of this controls, setting the tab order too.  But when i compile my form and run it, the cursor sticks at the first textbox field when I press the enter key, not if I use the tab key or mouse, Do we have to make a code for every textfield just to move to another textbox or other control

thank you


Answer this question

To move from one textbox field to another

  • Wawan K.

    thanks to both of you...now i got it workSmile

  • JustJF

    Hi,


    Yup, your quite right there. You must create a routine that sends a focus to other controls when you press the enter key. To do this easier, you could create an event that handles all of the Keypress events of your controls and just use sendkeys.sendwait("{TAB}"); to emulate the enter key as a tab key...

    private void keypressHandler(object sender, KeyPressEventArgs e) {
       if (e.KeyChar = Keys.Enter) {
          SendKeys.SendWait("{TAB}");
       }
    }



    cheers,


    Paul June A. Domag

  • Paz 9000

    Paul's code has a typo (was missing an equal sign) - I am pasting the correct code (fixing his original snip)

    private void keypressHandler(object sender, KeyPressEventArgs e) {
       if (e.KeyChar == Keys.Enter) {
          SendKeys.SendWait("{TAB}");
       }
    }



    Regards,
    Saurabh Nandu
    www.MasterCSharp.com
    www.AksTech.com

  • Ken_L

    Hi,


    Whew... Didn't catch that... THanks for correcting it though...Smile







    cheers,


    Paul June A. Domag

  • Dekagon

    Thanks Paul, I try it but it generate an error "Cannot implicitly convert 'char' to 'bool'...

  • kgy

    This would not work for me. I had to use (e.KeyChar == 13) because it would not compile. 13 is the char for the Enter key.
  • To move from one textbox field to another