Results 1 to 6 of 6

Thread: [RESOLVED] Looking for how to allow the user to be able to us the Enter key to exit a textbox

  1. #1

    Thread Starter
    Junior Member VicRauch's Avatar
    Join Date
    Mar 2009
    Posts
    18

    Resolved [RESOLVED] Looking for how to allow the user to be able to us the Enter key to exit a textbox

    I'm looking for what will allow the user to be able to use the Enter key to exit a TextBox control.

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Looking for how to allow the user to be able to us the Enter key to exit a textbo

    Hey,

    Depending on the situation, you could set the AcceptButton property of the form to be the button that you want to click when the user hit's enter. i.e. the save button. That way when the user hits enter, that code is called.

    Without some more information on what exactly you are trying to achieve, it is difficult to advise further.

    Hope that helps!!

    Gary

  3. #3
    Junior Member
    Join Date
    Jul 2007
    Location
    Bergen, Norway
    Posts
    31

    Re: Looking for how to allow the user to be able to us the Enter key to exit a textbo

    Well, you can always simply catch the enter key in the keydown event handler and move the focus to whatever other control you want.

  4. #4
    Member
    Join Date
    May 2001
    Posts
    50

    Re: Looking for how to allow the user to be able to us the Enter key to exit a textbo


  5. #5
    Member Cyrax.NET's Avatar
    Join Date
    Feb 2007
    Posts
    54

    Re: Looking for how to allow the user to be able to us the Enter key to exit a textbo

    how do you mean exit a textbox? they enter into it, type some stuff and after pressing enter, focus goes elsewhere?

    i'd catch the enter key event:


    Code:
    Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
    
            If e.KeyCode = Keys.Enter Then
    
                 'Do whatever, focus on next textbox, run a new method etc
    
           End If
    
    End Sub

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Looking for how to allow the user to be able to us the Enter key to exit a textbo

    maybe something like this

    Code:
        Private Sub TextBox1_KeyDown(ByVal sender As Object, _
                                     ByVal e As System.Windows.Forms.KeyEventArgs) _
                                     Handles TextBox1.KeyDown, TextBox2.KeyDown
            If e.KeyCode = Keys.Enter Then
                SelectNextControl(DirectCast(sender, TextBox), True, True, False, True)
            End If
        End Sub
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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