15,959,474 members
1.00/5 (1 vote)
See more:
Hi, I want to change a label to three different colors according to the timer control.
The code I have so far is:
VB
```If Label1.ForeColor = Color.Orange Then
Label2.ForeColor = Color.White
Label3.ForeColor = Color.Green
ElseIf Label2.ForeColor = Color.Orange Then
Label1.ForeColor = Color.Green
Label3.ForeColor = Color.White
ElseIf Label3.ForeColor = Color.White Then
Label2.ForeColor = Color.Green
Label3.ForeColor = Color.Orange
End If
```

Posted
Updated 18-Mar-11 5:02am
v3

## Solution 2

VB
```Dim xi As Integer = 0
Dim yi As Integer = 0
Dim zi As Integer = 0
<pre lang="vb">Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If xi &lt; 250 Then
xi = xi + 10
End If

If xi = 250 Then
If yi &lt; 250 Then
yi = yi + 10
End If
If yi = 250 Then
zi = zi + 10
If zi = 250 Then
zi = 0
yi = 0
xi = 0
End If
End If
End If
Label8.ForeColor = ColorTranslator.FromOle(RGB(xi, yi, zi))
Label9.ForeColor = ColorTranslator.FromOle(RGB(zi, yi, xi))
Label10.ForeColor = ColorTranslator.FromOle(RGB(yi, xi, zi))
Label11.ForeColor = ColorTranslator.FromOle(RGB(xi, zi, yi))

End Sub</pre>```

## Solution 1

All you have to do is include a Timer in your program.
You can do it using the designer (drag it from the tool box and set the properties) or in code:
`Private Shared WithEvents changeColour As New System.Windows.Forms.Timer()`
```changeColour.Interval = 500 ' Half a second
changeColour.Start()```

```Private Shared Sub changeColour_tick(myObject As [Object], myEventArgs As EventArgs) _
Handles myTimer.Tick
If Label1.ForeColor = Color.Orange Then
Label2.ForeColor = Color.White
Label3.ForeColor = Color.Green
ElseIf Label2.ForeColor = Color.Orange Then
Label1.ForeColor = Color.Green
Label3.ForeColor = Color.White
ElseIf Label3.ForeColor = Color.White Then
Label2.ForeColor = Color.Green
Label3.ForeColor = Color.Orange
End If
End Sub```

Posted a bit of cr@p VB code - I just did a verbatim translation from C# and forgot how crippled VB is... = OriginalGriff[/edit]

v2
sima2011 18-Mar-11 11:00am
ya i done it
If Label1.BackColor = Color.Green Then
Label1.BackColor = Color.White
Label2.BackColor = Color.Green
Label3.BackColor = Color.Orange
ElseIf Label1.BackColor = Color.White Then
Label1.BackColor = Color.Orange
Label2.BackColor = Color.White
Label3.BackColor = Color.Green
ElseIf Label1.BackColor = Color.Orange Then
Label1.BackColor = Color.Green
Label2.BackColor = Color.Orange
Label3.BackColor = Color.White
End If