Here try this.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Put this in your load event
TextBoxEvents(Me.Controls)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
Add two sub proceedures without a handles clause
Private Sub txtBox_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs)
CType(sender, TextBox).BackColor = Color.Blue
End Sub
Private Sub txtBox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
CType(sender, TextBox).BackColor = Color.Gray
End Sub
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Then add this Sub. This should be close to what you are looking for
Private Sub TextBoxEvents(ByVal contin As Control.ControlCollection)
Dim foundcontrol As Control
For Each foundcontrol In contin
If foundcontrol.GetType.ToString = "System.Windows.Forms.TextBox" Then
AddHandler CType(foundcontrol, TextBox).GotFocus, AddressOf txtBox_GotFocus
AddHandler CType(foundcontrol, TextBox).LostFocus, AddressOf txtBox_LostFocus
'CType(foundcontrol, TextBox).BackColor = Color.Blue
End If
If foundcontrol.Controls.Count <> 0 Then
TextBoxEvents(foundcontrol.Controls)
End If
Next foundcontrol
End Sub
DotNetDoc
M.C.S.D.
---------------------------------------
Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein