|
|
Title | Make a label blink |
Keywords | blink, label, color, flash |
Categories | Controls, Graphics |
|
|
Use a Timer. When the Timer fires, switch the label's ForeColor and BackColor properties.
This example stores the colors each label should use when the program is in one of two states. Form_Load initializes the controls' colors.
|
|
' Initialize blink colors.
Private Sub Form_Load()
' lblBlink(0)
' State 0 = Black on background color
' State 1 = Disappears
ForeColors(0, 0) = vbBlack
BackColors(0, 0) = BackColor
ForeColors(1, 0) = BackColor
BackColors(1, 0) = BackColor
' lblBlink(1)
' State 0 = Disappears
' State 1 = Red
ForeColors(0, 1) = BackColor
BackColors(0, 1) = BackColor
ForeColors(1, 1) = vbRed
BackColors(1, 1) = BackColor
' lblBlink(2)
' State 0 = Black
' State 1 = White
ForeColors(0, 2) = vbBlack
BackColors(0, 2) = BackColor
ForeColors(1, 2) = vbWhite
BackColors(1, 2) = BackColor
' Perform the first blink to set valid colors.
tmrBlink_Timer
End Sub
|
|
When the Timer event fires, the program toggles the state value between 0 and 1. Then for each label control, it looks up the foreground and background colors it should use to display the label in the current state.
|
|
Private Sub tmrBlink_Timer()
Static state As Integer
Dim i As Integer
state = 1 - state
For i = 0 To 2
lblBlink(i).ForeColor = ForeColors(state, i)
lblBlink(i).BackColor = BackColors(state, i)
Next i
End Sub
|
|
|
|
|
|