GotFocus Question
Ok,
Is there a way to write code behind say 1 gotfocus of a textbox and have it affect all textboxs? If I have 20 textboxes on screen I dont want to have to put code in 20 places. Just 1 place. Is this possible?
For example, if I want to change the background color of all the textboxes that have focus, without writing in the gotfocus of every textbox.
Thanks in advance..
jb
[415 byte] By [
jcb1269] at [2007-11-11 10:27:37]

# 1 Re: GotFocus Question
Sure, just list all the textboxes in the event's Handles clause:
Private Sub TextBox_GotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles TextBox1.GotFocus, TextBox2.GotFocus ' , etc.
A cleaner approach is to create a new class which inherits from TextBox and which overrides the OnGotFocus method with the desired code. Then, instead of using the standard TextBox control on your form, use the inherited class: http://forums.dev-archive.com/showpost.php?p=473865&postcount=2
# 3 Re: GotFocus Question
Phil,
That's what I was doing but I had my sub doing the wrong thing so it wasn't working. I figured it out and works fine.
Thank you for your help.
jb