Dan,
I have an inkling i'll have to define my own textBox class, is that right?
Any pointers?
In addition to the brute force method of using AddHandler that the others
discussed, a couple of other possibilities include:
1) you can manually add each handler using the Handles syntax.
Private Sub TextBox_KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles TextBox1.KeyPress, TextBox2.KeyPress, _
TextBox3.KeyPress, TextBox4.KeyPress
MsgBox(e.KeyChar)
End Sub
2) you can derive your own TextBox class and encapsulate all the events
(subs, functions, properties) in a single class (which is not your form
class).
Public Class TextBoxEx
Inherits TextBox
Protected Overrides Sub OnKeyPress(ByVal e As
System.Windows.Forms.KeyPressEventArgs)
MyBase.OnKeyPress(e)
' Your logic here
End Sub
End Class
I will use the first above if I only have a handful of text boxes. I will
use the second above if I have multiple events to handle in addition to
needing to have additional information (properties) associated with each
TextBox. Or I need to handle the same stuff on multiple forms...
I will use the brute force method, if I only have a single event that I need
to handle on a single form (on multiple text boxes), which is rare...
The biggest problem with the second method above, is getting the control to
appear on the tool box so its easy to use. I normally manually change the
source to use my textbox over the normal text box...
Hope this helps
Jay