Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm assuming you are trying to enable navigation of your form with the enter and arrow keys. </p> <p>If that is the case:</p> <ol> <li>Delete that code</li> <li>Select the design view of the form</li> <li>Right click on the VB toolbar and make sure the "layout" toolbar is visible </li> <li>Click on the button on the far right called "Tab Order" </li> <li>Click on each control in the order that you want </li> <li>Set the "KeyPreview" property of the form to TRUE </li> </ol> <p>Then add the following code:</p> <pre><code>Private Sub Form1_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp If Me.ActiveControl.GetType Is GetType(DateTimePicker) Then 'DateTimePicker Select Case e.KeyCode Case Keys.Enter Me.SelectNextControl(Me.ActiveControl, True, True, True, True) 'forwards End Select ElseIf Me.ActiveControl.GetType Is GetType(TextBox) AndAlso Not DirectCast(Me.ActiveControl, TextBox).Multiline Then 'normal Textbox Select Case e.KeyCode Case Keys.Up Me.SelectNextControl(Me.ActiveControl, False, True, True, True) 'backwards Case Keys.Down, Keys.Enter Me.SelectNextControl(Me.ActiveControl, True, True, True, True) 'forwards End Select ElseIf Me.ActiveControl.GetType Is GetType(TextBox) AndAlso DirectCast(Me.ActiveControl, TextBox).Multiline Then 'multiline Textbox - ignore Else 'all other controls Select Case e.KeyCode Case Keys.Up Me.SelectNextControl(Me.ActiveControl, False, True, True, True) 'backwards Case Keys.Down, Keys.Enter Me.SelectNextControl(Me.ActiveControl, True, True, True, True) 'forwards End Select End If End Sub </code></pre> <p>The up/down arrow keys are actually used by the DateTimePicker and so need to be excluded as navigation commands for it. Conversely, a multiline textbox uses the ENTER key and therefore ENTER must be excluded as a navigation command in that case.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload