Keydown procedure?

Inconnu_nom

New member
Joined
Jan 18, 2005
Messages
2
Programming Experience
1-3
How can you set the keydown procedure in vb.net?
I need snggrav to be equal to -30 when up is pressed. am i on the right track? this is all the code i have pretaining to it
Private Sub Form1_Keydown(ByVal keycode As Integer, ByVal shift As Integer)

Select Case Keys.KeyCode

Case Keys.Up

snggrav = -30

End select

End sub
 
The code you have looks like it could be VB6.
In VB.NET the code would look more like this:
VB.NET:
Private Sub Form1_KeyUp(ByVal sender As Object, _
  ByVal e As System.Windows.Forms.KeyEventArgs) _
  Handles MyBase.KeyUp
    If e.KeyCode = Keys.Up Then
        snggrav = -30
    End If
End Sub
To have the IDE create the signature of the procedure for you: in the code window look for the two dropdown lists at the top. In the left one, select '(Base Class Events)' for events pertaining to the class you are in (you can also select other controls as well). In the right dropdown, select the event you want to hadle and the IDE will either create the procedure outline if it doesn't exist or place the cursor in that procedure.
 
Here is code for an 'F3' keypress on a grid...

Private Sub Grid1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Grid1.KeyDown
' Check if F3 Key is pressed.
If e.KeyCode = Keys.F3 Then
Try
tCurrentUnit = Grid1.Columns("Units").Value
Catch ex As Exception
End Try
End If
End Sub
 
Back
Top