Assuming you want to do this to all text controls on the form, add the following to subs
Private Sub Text_Enter(sender As System.Object, e As System.EventArgs)
DirectCast(sender, TextBox).BackColor = Color.Yellow
End Sub
Private Sub Text_Leave(sender As System.Object, e As System.EventArgs)
DirectCast(sender, TextBox).BackColor = Color.White
End Sub Then add the following for the form load event handler
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
For Each ctrl As Control In Me.Controls
If TypeOf (ctrl) Is TextBox Then
AddHandler ctrl.Enter, AddressOf Text_Enter
AddHandler ctrl.Leave, AddressOf Text_Leave
End If
Next
End Sub The first two subs will supply the handler code for the enter and leave events. The form load code will add those handlers to all textboxes.
I have a new kitten (as of 4 days ago) who is making these postings somewhat difficult, although on the bright side, she is creating some very cryptic passwords as she chases the cursor while dancing on my keyboard.
Reverend Jim
Posting Shark
Moderator
1,167 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159