AdvancedHMI Software
General Category => Support Questions => Topic started by: MrPike on December 09, 2015, 08:06:48 PM
-
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!
-
For each control you want to change, set the Tag property to 1, then use this 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
-
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
-
I assume you mean a BasicIndicator since the BasicLabel does not have a Color1 Property.
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
-
Yes. You are correct. I'm using the BasicIndicator. This works great. Sure saves a lot of typing. Thanks.