General Category > Support Questions
Changing color of multiple labels at once
(1/1)
MrPike:
Hi, I'm looking for some code help that will allow me to change the SelectColor of many BasicLabels at once. I have a check box that when unchecked I want basiclabels 1 thru 23 to be color 1. I know I can list each label in an If Then statement but was hoping to do this with less code, maybe in a line or two. Thanks in advance!
Archie:
For each control you want to change, set the Tag property to 1, then use this code:
--- Code: --- Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
For i = 0 To Me.Controls.Count - 1
If Me.Controls(i).Tag = "1" Then
Me.Controls(i).BackColor = Color.Green
End If
Next
End If
End Sub
--- End code ---
MrPike:
Thanks Archie, I'm actually trying to select the color1 property of the basiclabel. Changing the backcolor does not accomplish what I need. I attached a pic and intellisense does not like it since color1 is not a member of 'System.Windows.Forms.control'. Any other tricks? Thanks
Archie:
I assume you mean a BasicIndicator since the BasicLabel does not have a Color1 Property.
--- Code: --- Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
For i = 0 To Me.Controls.Count - 1
If Me.Controls(i).Tag = "1" Then
If TypeOf (Me.Controls(i)) Is AdvancedHMIControls.BasicIndicator Then
Dim c As AdvancedHMIControls.BasicIndicator = DirectCast(Me.Controls(i), AdvancedHMIControls.BasicIndicator)
c.Color1 = Color.Green
End If
End If
Next
End If
End Sub
--- End code ---
MrPike:
Yes. You are correct. I'm using the BasicIndicator. This works great. Sure saves a lot of typing. Thanks.
Navigation
[0] Message Index
Go to full version