How to move the Cursor from a testbox control to the next one using ENTER key

Hi,

I'm new with VC#, I want to put some code on a textbox control or what ever control to move to other controls when I press the enter key.

So far, my small app uses TAB KEY to move to the next controls on my windows forms.

How can I accomplice this in C# VFP & VB is quite easy, but C#, I dont have any idea how to do it. Can somebody show me a code or sample to do this

Thanks.

 




Answer this question

How to move the Cursor from a testbox control to the next one using ENTER key

  • shango

    A lot of sample code on the link, but the nearest code similar to VB is the code below:

    <PRE>private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
    if( e.KeyCode == Keys.Enter )
    {
    // Mark the handled flag so this
    // key won't be processed.
    e.Handled = true;
    textBox2.Focus();
    }
    }

    private void textBox2_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
    if( e.KeyCode == Keys.Enter )
    {
    // Mark the handled flag so this
    // key won't be processed.
    e.Handled = true;
    textBox1.Focus();
    }</PRE>

    Actually, in Visual Foxpro, its automatic, no need to put some code, pressing enter key will go to next control with the next TAB key order. VFP has KEYPRES property that you can handle events with the any key being press on a forms.


    }



  • MADLAX

    There is a posting on the same topic at http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=354329&SiteID=1

    Regards,

    Nitin


  • pramodh

    Thanks Nitin, I check from the link.

  • How to move the Cursor from a testbox control to the next one using ENTER key