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

  • Pyush Kumar

    Hi,


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







    cheers,


    Paul June A. Domag

  • Yozz

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

  • Sowbhagya

    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

  • Shrikant24227

    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.
  • Mauro Inzerillo

    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

  • Jim Webb

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

  • To move from one textbox field to another