Dead easy:
[code]
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
' enter handling code here, using members of e object...
End Sub
[code]
You can copy and paste code, but to get the development environment to show it automatically:
1) When you are looking at the code for your form, look at the top of the screen.
2) After the menu bar and the tool bar, there are a load of tabs, one for each code/designer window you have open.
3) Just under these tabs are two combo boxes - the one on the left will have something like 'Form1' in it, the one on the right will have something like '(Declarations)' in it.
4) If you drop-down the box on the left, you'll see that all the controls you've added to the form are listed. Select the control you want to add an event handler for.
5) Then, drop down the right-hand combo. This will list all the events for the selected object. Events which already have handlers are listed in
bold
Advanced:
If you want a method to handle events for two or more controls, create the handler as I've described above. You'll notice that after the method declaration there's a handles keyword:
Code:
Private Sub OnKeyPress(sender as Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
If you put a comma, you can then type the name of a new [Control].[Event] for the routine to handle (intellisense will help you with this), i.e.
Code:
Private Sub OnKeyPress(sender as Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress, TextBox2.KeyPress
Hope this sorts you out