i want to be able to loop through all the textboxes on a form and when each textbox has focus, i want to set the background color to (somecolor..like blue) and set it back to white when the textbox loses focus...
The function will do the job for you. You need to pass it the form. It also looks to see if you have any container objects on the form panel etc.. . You call the function like this.
ClearChildText(Me.Controls)
Private Sub ClearChildText(ByVal contin As Control.ControlCollection)
Dim foundcontrol As Control
For Each foundcontrol In contin
If foundcontrol.GetType.ToString = "System.Windows.Forms.TextBox" Then
CType(foundcontrol, TextBox).BackColor= Color.Blue
End If
If foundcontrol.Controls.Count <> 0 Then
ClearChildText(foundcontrol.Controls)
End If
Next foundcontrol
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
i tried your suggestion and it colors all the textbox backgrounds on my form to blue.... i just want a textbox's backcolor to change when it receives focus...
thanks for your help, i'm gonna see if i can use your example to do what i'm trying to do....
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
DocNetDoc: Bless you. I have struggled mightily to find a reliable procedure to reset different types of controls on my forms and you have shown me the way. Your solution is elegant and concise, two hallmarks of excellence in coding. My sincerest thanks for your solution to a problem that had been gnawing at me quite a while.
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.