changing forecolor of groupbox children

f1sh3r

Senior member
Oct 9, 2004
636
0
0
i have a bunch of labels (17) contained within a group box.

i want to be able to change the color of the label text of all of them with one command. can it be done?

this is the logic i wanted to follow. very simple, but of course its not right.

groupbox1.children.forecolor = color.black


tia
 

KB

Diamond Member
Nov 8, 1999
5,406
389
126
There is no one command but you might create a subroutine from this code, or extend the GroupBox class to allow your syntax:

For Each ctl As Control in groupbox1.Controls
If TypeOf (ctl) Is System.Windows.Forms.Label Then
Dim l As Label = ctl
l.ForeColor = Color.Black
End If
Next
 

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
KB's solution works fine, it's what i'd do. I THINK though, that if you change the forecolor of the groupbox, all labels will inherit it automatically. But, this will change the groupbox's title also.

One of the reasons your logic wont work (and isnt implemented) is because its possible that a child of the groupbox wont have the forecolor property.