Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Transfer Cursor via Enter Key Input

Transfer Cursor via Enter Key Input

Scheduled Pinned Locked Moved Visual Basic
help
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Duane in Japan
    wrote on last edited by
    #1

    First time here, thanks in advance for any help. I am currently finishing up a project that does not use Buttons and I have been able to move around through 50 user input boxes via the TAB key. I have used _Validating so when I TAB out of the block of code, the code is activated automatically. TextBox1_Validating..............Checkbox1_Validating............, its all good and it all works. I only need the Checkboxes under certain scenarios and I cannot program and infinite number of scenarios, so, to make my project completely Button and mouse free, I would like to move from a textbox to a checkbox the sits right next to it when needed by pushing the Enter Key. I have done my homework and have not seen anything of the sort, I do not need the Enter key anywhere else in my code nor does it work even if I accidently bump it. Duane in Japan Sorry, I have VB Studio '05.

    M 1 Reply Last reply
    0
    • D Duane in Japan

      First time here, thanks in advance for any help. I am currently finishing up a project that does not use Buttons and I have been able to move around through 50 user input boxes via the TAB key. I have used _Validating so when I TAB out of the block of code, the code is activated automatically. TextBox1_Validating..............Checkbox1_Validating............, its all good and it all works. I only need the Checkboxes under certain scenarios and I cannot program and infinite number of scenarios, so, to make my project completely Button and mouse free, I would like to move from a textbox to a checkbox the sits right next to it when needed by pushing the Enter Key. I have done my homework and have not seen anything of the sort, I do not need the Enter key anywhere else in my code nor does it work even if I accidently bump it. Duane in Japan Sorry, I have VB Studio '05.

      M Offline
      M Offline
      Marcus J Smith
      wrote on last edited by
      #2

      Add the following line to your form load for each control that it is relevant for.

      AddHandler uxControlWhereEnteredKeyPressed.KeyPress, AddressOf Me.NameOfEventToHandleThis

      Here's the event.

      Private Sub NameOfEventToHandleThis(ByVal sender As Object, ByVal e As KeyPressEventArgs)
      If e.KeyChar = Chr(13) Then
      SelectNextControl(Me.ActiveControl, True, False, True, True)
      e.Handled = True
      End If
      End Sub

      The False will stop on Non-tab stop items so just make sure your tab order is in the correct order but set the CheckBoxes to TabStop = False. If you want to speed up adding the handler use the following snippet of code.

      For Each ControlOnForm In Me.Controls
      If TypeOf ControlOnForm Is TextBox Then
      DirectCast(ControlOnForm, TextBox).KeyPress, AddressOf Me.NameOfEventToHandleThis
      End If
      Next

      I hope this helps.


      CleaKO

      "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

      D 2 Replies Last reply
      0
      • M Marcus J Smith

        Add the following line to your form load for each control that it is relevant for.

        AddHandler uxControlWhereEnteredKeyPressed.KeyPress, AddressOf Me.NameOfEventToHandleThis

        Here's the event.

        Private Sub NameOfEventToHandleThis(ByVal sender As Object, ByVal e As KeyPressEventArgs)
        If e.KeyChar = Chr(13) Then
        SelectNextControl(Me.ActiveControl, True, False, True, True)
        e.Handled = True
        End If
        End Sub

        The False will stop on Non-tab stop items so just make sure your tab order is in the correct order but set the CheckBoxes to TabStop = False. If you want to speed up adding the handler use the following snippet of code.

        For Each ControlOnForm In Me.Controls
        If TypeOf ControlOnForm Is TextBox Then
        DirectCast(ControlOnForm, TextBox).KeyPress, AddressOf Me.NameOfEventToHandleThis
        End If
        Next

        I hope this helps.


        CleaKO

        "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

        D Offline
        D Offline
        Duane in Japan
        wrote on last edited by
        #3

        Thanks for your assistance, sorry, I am still a bit new to naming conventions, I have been sticking to the default names so I am not sure what to insert into your code. This includes the Form Load line of code also please. I have set the TAB index up to what I believe is by your instructions. Here is a piece of what I am working with. Where do I insert your code and how do I name the events. Private Sub TextBox5_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox5.Validating Dim Box2 As Double = 0 Dim Box5 As Double = 0 If TextBox5.Text.Length = 0 Then 'http://msdn2.microsoft.com/en-us/library/139z2azd.aspx, MsgBox MsgBox("A 'B1' value is required.", MsgBoxStyle.Exclamation) e.Cancel = True ElseIf Not IsNumeric(TextBox5.Text) Then MsgBox("This 'B1' value is not numeric.", MsgBoxStyle.Exclamation) e.Cancel = True 'http://msdn2.microsoft.com/en-us/library/system.windows.forms.checkbox.checked(VS.80).aspx, CheckBox ElseIf CheckBox2.Checked Then e.Cancel = False Else Box2 = CDbl(TextBox2.Text) Box5 = CDbl(TextBox5.Text) TextBox3.Text = CStr(Box5 + 1) TextBox4.Text = CStr(Box2 - Box5) End If If Box5 <= 0 Then MsgBox("Your 'B1' value must be greater than zero.", MsgBoxStyle.Exclamation) ElseIf e.Cancel = True Then End If TextBox35.Clear() TextBox36.Clear() TextBox37.Clear() TextBox38.Clear() TextBox39.Clear() End Sub Private Sub CheckBox2_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles CheckBox2.Validating TextBox35.Text = TextBox5.Text TextBox36.Focus() End Sub If needed right now, I would like to hit the enter key and go from textbox5 to checkbox2. Duane in Japan

        M 1 Reply Last reply
        0
        • D Duane in Japan

          Thanks for your assistance, sorry, I am still a bit new to naming conventions, I have been sticking to the default names so I am not sure what to insert into your code. This includes the Form Load line of code also please. I have set the TAB index up to what I believe is by your instructions. Here is a piece of what I am working with. Where do I insert your code and how do I name the events. Private Sub TextBox5_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox5.Validating Dim Box2 As Double = 0 Dim Box5 As Double = 0 If TextBox5.Text.Length = 0 Then 'http://msdn2.microsoft.com/en-us/library/139z2azd.aspx, MsgBox MsgBox("A 'B1' value is required.", MsgBoxStyle.Exclamation) e.Cancel = True ElseIf Not IsNumeric(TextBox5.Text) Then MsgBox("This 'B1' value is not numeric.", MsgBoxStyle.Exclamation) e.Cancel = True 'http://msdn2.microsoft.com/en-us/library/system.windows.forms.checkbox.checked(VS.80).aspx, CheckBox ElseIf CheckBox2.Checked Then e.Cancel = False Else Box2 = CDbl(TextBox2.Text) Box5 = CDbl(TextBox5.Text) TextBox3.Text = CStr(Box5 + 1) TextBox4.Text = CStr(Box2 - Box5) End If If Box5 <= 0 Then MsgBox("Your 'B1' value must be greater than zero.", MsgBoxStyle.Exclamation) ElseIf e.Cancel = True Then End If TextBox35.Clear() TextBox36.Clear() TextBox37.Clear() TextBox38.Clear() TextBox39.Clear() End Sub Private Sub CheckBox2_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles CheckBox2.Validating TextBox35.Text = TextBox5.Text TextBox36.Focus() End Sub If needed right now, I would like to hit the enter key and go from textbox5 to checkbox2. Duane in Japan

          M Offline
          M Offline
          Marcus J Smith
          wrote on last edited by
          #4

          If you double click on the form itself that is the form load event. You would put the handler piece in that method. The other part would be it's own function and would happen when you hit enter in the textboxes that you assign a handler to. The validating would still occur and if it didnt validate correctly you would just call e.Cancel = True in the validating event.


          CleaKO

          "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

          1 Reply Last reply
          0
          • M Marcus J Smith

            Add the following line to your form load for each control that it is relevant for.

            AddHandler uxControlWhereEnteredKeyPressed.KeyPress, AddressOf Me.NameOfEventToHandleThis

            Here's the event.

            Private Sub NameOfEventToHandleThis(ByVal sender As Object, ByVal e As KeyPressEventArgs)
            If e.KeyChar = Chr(13) Then
            SelectNextControl(Me.ActiveControl, True, False, True, True)
            e.Handled = True
            End If
            End Sub

            The False will stop on Non-tab stop items so just make sure your tab order is in the correct order but set the CheckBoxes to TabStop = False. If you want to speed up adding the handler use the following snippet of code.

            For Each ControlOnForm In Me.Controls
            If TypeOf ControlOnForm Is TextBox Then
            DirectCast(ControlOnForm, TextBox).KeyPress, AddressOf Me.NameOfEventToHandleThis
            End If
            Next

            I hope this helps.


            CleaKO

            "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

            D Offline
            D Offline
            Duane in Japan
            wrote on last edited by
            #5

            This is just one of ten exact calculation events, with the code that you gave, with limited infor from me, it worked but some code later in the calculator was not working properly. The Enter key did something to the CheckBox and its name (CheckBox + Label) but it did not physically check the box, since my entire project is about Validating and the Checkbox was not actually Checked then code later did not run as intended. Played with your code unnecessarily and played with some of my own guessing until I just had to add in CheckBox2.Checked = True. within your code so more of my code could run later. Thanks again to all for this help, sorry for taking so long to get back, this forum moves fast. I put the correct line of code in the Form.Load event up top too. Private Sub TextBox5_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox5.Validating Dim Box2 As Double = 0 Dim Box5 As Double = 0 TextBox5.SelectAll() If TextBox5.Text.Length = 0 Then 'http://msdn2.microsoft.com/en-us/library/139z2azd.aspx, MsgBox MsgBox("A 'B1' value is required.", MsgBoxStyle.Exclamation) e.Cancel = True ElseIf Not IsNumeric(TextBox5.Text) Then MsgBox("This 'B1' value is not numeric.", MsgBoxStyle.Exclamation) e.Cancel = True 'http://msdn2.microsoft.com/en-us/library/system.windows.forms.checkbox.checked(VS.80).aspx, CheckBox ElseIf CheckBox2.Checked Then e.Cancel = False Else 'http://msdn2.microsoft.com/en-us/library/ewf8xx62(VS.80).aspx, Convertion Box2 = CDbl(TextBox2.Text) Box5 = CDbl(TextBox5.Text) TextBox3.Text = CStr(Box5 + 1) TextBox4.Text = CStr(Box2 - Box5) End If If Box5 <= 0 Then MsgBox("Your 'B1' value must be greater than zero.", MsgBoxStyle.Exclamation) ElseIf e.Cancel = True Then End If TextBox35.Clear() TextBox36.Clear() TextBox37.Clear() TextBox38.Clear() TextBox39.Clear() End Sub Private Sub TextBox5_Validating(ByVal sender As Object, ByVal e As KeyPressEventArgs) If e.KeyChar = Chr(13) Then SelectNextControl(Me.ActiveControl, True, False, True, True) CheckBox2.Checked = True e.Handled = True End If End Sub Private Sub CheckBox2_Validating(ByVal sender As System.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups