Question Control Focus - Backcolor - multiple controls

Simple Man

Member
Joined
Jul 7, 2010
Messages
13
Programming Experience
5-10
Is there a more efficient/easier way changing the backcolor of a control when it has focus and lost focus?

Let's say I've got 10 text boxes. Right now I would have 20 different events...10 for Enter event and 10 for Leave event. Of course, entering would change the back color to "green" and leaving would change it back to "white".

Is there another method of doing this?

Keep in mind, there could be multiple comboboxes, textboxes, etc.

Thanks.

Nick
 
How about...
VB.NET:
For Each c As Control In Me.Controls
            If TypeOf (c) Is TextBox Then
                AddHandler c.GotFocus, AddressOf MakeBGColorGreen
                AddHandler c.LostFocus, AddressOf MakeBGColorWhite
            End If
        Next
 
Just select all controls in designer and double click the event in Properties window (events view).
 
ALX,

Your solution worked. I am still new to vb.net and still learning.

JohnH...I took a look at your suggestion but it didn't work. If I try this it take the last control I selected and creates the event only for that control. Unless I'm doing something wrong...

Thanks for the replies.

Nick
 
You have to select multiple objects. Ctrl-mouseclick them all.
 
Back
Top