KeyDown Event ?

R

RS

I would like to interface with the Win32 API and I need the HWND handle
to Form1 ( I'm assuming it is Me.Handle) and I need Form1 to respond to
keyboard input. Using the information from a previous question I have
entered the following into my IDE and cannot get any response:


Friend WithEvents Form1 As System.Windows.Forms.Form

Private Sub Form1_KeyDown(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles _
Form1.KeyDown

Dim i As Integer = 0

Select Case e.KeyCode
Case Keys.Left
i += 1
'etc..................
End Select

End Sub

How can I get my code to respond to keyboard events ?

TIA RS
 
T

Tom Spink

Friend WithEvents Form1 As System.Windows.Forms.Form

What in the name of Option Strict is that!! :) SCNR

Are you calling this code from within a form? If so, then you don't need
that line.

Your Handles clause, on the KeyDown method, should read Handles
MyBase.KeyDown

Also, you *may* need to set your form's KeyPreview property to True.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"


I would like to interface with the Win32 API and I need the HWND handle
to Form1 ( I'm assuming it is Me.Handle) and I need Form1 to respond to
keyboard input. Using the information from a previous question I have
entered the following into my IDE and cannot get any response:


Friend WithEvents Form1 As System.Windows.Forms.Form

Private Sub Form1_KeyDown(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles _
Form1.KeyDown

Dim i As Integer = 0

Select Case e.KeyCode
Case Keys.Left
i += 1
'etc..................
End Select

End Sub

How can I get my code to respond to keyboard events ?

TIA RS
 
R

RS

Alrighty : ) , and thank you.

I would like to interface with the Win32 API and I need the HWND handle
to Form1 ( I'm assuming it is Me.Handle) and I need Form1 to respond to
keyboard input. Using the information from a previous question I have
entered the following into my IDE and cannot get any response:


Friend WithEvents Form1 As System.Windows.Forms.Form

Private Sub Form1_KeyDown(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles _
Form1.KeyDown

Dim i As Integer = 0

Select Case e.KeyCode
Case Keys.Left
i += 1
'etc..................
End Select

End Sub

How can I get my code to respond to keyboard events ?

TIA RS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top