Making the TextColor of Multiple Label Controls One Color At Once


I have some windows where there are multiple labels defining multiple text boxes. I want the user to be able to change the text color of these labels. The actual text does not change, just the text color.

To change the text color I have to do this:

lbl1.TextColor = RGB(255, 128, 0) lbl2.TextColor = RGB(255, 128, 0) etc..

I was wondering if I could make sort of a control array and write some code that would change all the label text colors with a limited number lines of code. Is that possible, or do I have to set each label control with one line of text each?

Any suggestions would be greatly appreciated.


Hi Jim
Yes, you can add the Labels to a control array (called a Control Set). Click a label and choose the Advanced inspector (the cog) - you’ll see the Control Set dropdown, from where you can create one. Then, add the other Labels to the Control Set in a similar fashion.

Next, just loop through the Control Set and change the TextColor. Something like this:

for i as integer = 0 to 4 // If you have 5 labels in your Control Set MyLabels(i).TextColor = RGB(255,128,0) next

A Control Set isn’t the same as an array, though, so you can’t use them exactly the same as one - there is no Ubound, for example.

Great! Thanks Gavin for the quick response. Thats exactly what I was looking for. I really appreciate it.

if you don’t want to use control set, you can set one of the properties ‘DataSource’ or ‘DataField’ to some word like ‘chgcolor’ and then loop through all the control and look for Label that has the word chgcolor.

      j=vForm.controlcount - 1
      for i = 0 to j
        SELECT CASE vCtrl
        CASE isa TextArea
          if Label(vctrl).DataSource="chgcolor" THEN
            vCtrlName= Label(vctrl).name
           Label(vctrl).TextColor = RGB(255,128,0)
          END IF
        next i