Results 1 to 7 of 7

Thread: Using Enter key when moving controls

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    105

    Using Enter key when moving controls

    Hi.

    How would i do it in my code if i Want to use an "ENTER" key when transferring control?

    thanks!

  2. #2
    Addicted Member macuiare's Avatar
    Join Date
    Jan 2009
    Posts
    229

    Re: Using Enter key when moving controls

    Hmm, not to sure what you mean, do you mean you push enter and the something moves? :/

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    105

    Re: Using Enter key when moving controls

    Yes.

    For example:

    Textbox1 TextBox2 TextBox3.

    After i input item on TextBox1 and I press ENTER, the control will go to TextBox2 and so on.

    Thanks.

  4. #4
    Member
    Join Date
    May 2001
    Posts
    50

    Re: Using Enter key when moving controls

    Try adding a KeyPress event handler to each textbox to detect when Enter is pressed and set the focus to the next box.

  5. #5
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Using Enter key when moving controls

    Hi,
    I think you mean that if you put some text in textbox1 the the carret goes to te next textbox2.
    If so you could try something like this:

    vb Code:
    1. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _
    2.     Handles TextBox1.KeyPress, TextBox2.KeyPress, TextBox3.KeyPress
    3.  
    4.         If Not TextBox1.Text = "" Then
    5.             If e.KeyChar = Chr(Keys.Enter) Then
    6.                 TextBox2.Focus()
    7.                 e.Handled = True
    8.             End If
    9.         End If
    10.  
    11.         If Not TextBox2.Text = "" Then
    12.             If e.KeyChar = Chr(Keys.Enter) Then
    13.                 TextBox3.Focus()
    14.                 e.Handled = True
    15.             End If
    16.         End If
    17.  
    18.         If Not TextBox3.Text = "" Then
    19.             If e.KeyChar = Chr(Keys.Enter) Then
    20.                 MsgBox("You filled all textboxes")
    21.                 e.Handled = True
    22.             Else
    23.                 TextBox3.Focus()
    24.             End If
    25.         End If
    26.  
    27.     End Sub

    Wkr,

    sparrow1
    Last edited by sparrow1; Mar 4th, 2009 at 06:31 AM.
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  6. #6
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Using Enter key when moving controls

    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  7. #7
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Using Enter key when moving controls

    Refer this
    Please mark you thread resolved using the Thread Tools as shown

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width