|
-
Aug 24th, 2004, 06:23 AM
#1
Thread Starter
Addicted Member
Form Key Down - RESOLVED
How can i make to add the key down event to all objects on my form?
I made a form with just 6 buttons, and i have to add to each buton manually.
But on the main form, i have a lot of objects, and just add key down to main form object don´t work.
Any tips?!
Thank you,
Guilherme Costa
Last edited by gccosta; Aug 24th, 2004 at 08:13 AM.
-
Aug 24th, 2004, 07:03 AM
#2
It is possible to have multiple handles statements for the same event, i.e. see the below example:
VB Code:
Private Sub Form1_KeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles MyBase.KeyDown, Button1.KeyDown, Button2.KeyDown
End Sub
-
Aug 24th, 2004, 07:04 AM
#3
Thread Starter
Addicted Member
It have some way to do all this handles automatically?
Thank you,
Guilherme
-
Aug 24th, 2004, 07:40 AM
#4
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim intCtlCounter as Integer
For intCtlCounter = 0 to me.Controls.Count - 1
addhandler me.Controls(intCtlCounter).KeyDown, _
addressof KeyPressed
next intCtlCounter
End Sub
Private sub KeyPressed (ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs)
msgbox (ctype(sender, control).name & _
" had the event!")
End Sub
-
Aug 24th, 2004, 07:40 AM
#5
Fanatic Member
this?
VB Code:
Class clicker
Sub New(ByVal c() As Control)
Dim i As Integer
For i = 0 To c.Length - 1
AddHandler c(i).KeyDown, AddressOf c_keydown
Next
End Sub
Sub c_keydown(ByVal sender As Object, ByVal e As KeyEventArgs)
' do something
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dummy As New clicker(New Control() {Me, Button1, Button2, Button3, _
Button4, Button5, TextBox1, TextBox2, TextBox3})
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|