using timers to flash label messages

G

Guest

is there a simple way to code a timer to make a warning label blink on and off?
Lets say I have a form with 3 textboxes and 4 labels plus one timer
object(labelTimer)and 2 buttons(start,stop).labels 1,2 and 3 are attached to
textboxes 1,2 and 3. label 4 is stand alone and needs to bink a warning while
calculations are being made(startButton click to stopButton click).The
interval should be 1/2 sec.
for instance: "Calculating Results" blinks at 1/2 sec intervals until the
stop button is clicked then "Calculations Complete" and visible = true when
the stop button is clicked.
I posted another question a few days ago concerning timespan structures and
you guys came through so maybe some guru can help the wannabe out here too?
thanks guys
 
Z

ZorpiedoMan

Here is a flash routine I wrote a few months ago. This won't work as
is. It is part of a rather complicated UserControl, but you can see how
the concept works. (The refresh method that this calls is what actually
changes the colors of the label based on the myLabelForeColor value.)


#Region "Flash"

Private myFlashTime As Long
Private Flasher As System.Threading.Timer
Private HoldForeColor As Color

Private myFlashWaitTime As Long = 0
Public Property FlashWaitTime() As Long
Get
Return myFlashWaitTime
End Get
Set(ByVal Value As Long)
myFlashWaitTime = Value
End Set
End Property

Private myFlashOnTime As Long = 500
Public Property FlashOnTime() As Long
Get
Return myFlashOnTime
End Get
Set(ByVal Value As Long)
myFlashOnTime = Value
End Set
End Property

Private myFlashOffTime As Long = 100
Public Property FlashOffTime() As Long
Get
Return myFlashOffTime
End Get
Set(ByVal Value As Long)
myFlashOffTime = Value
End Set
End Property

Public Sub StartFlashing()
If myFlashOnTime = 0 Or myFlashOffTime = 0 Then Exit Sub
myFlashTime = myFlashOnTime
HoldForeColor = myLabelForeColor
Flasher = New System.Threading.Timer(AddressOf Flash, Nothing,
myFlashWaitTime, myFlashOnTime)
End Sub

Public Sub StopFlashing()
If Flasher Is Nothing Then Exit Sub
Flasher.Change(System.Threading.Timeout.Infinite, 0)
Flasher = Nothing
Me.myLabelForeColor = HoldForeColor
Refresh()
End Sub

Private Sub Flash(ByVal state As Object)

'state = Nothing
If Me.FindForm Is Nothing Or Me.Parent Is Nothing Or Me Is
Nothing Or Flasher Is Nothing Then
StopFlashing()
Exit Sub
End If

If myLabelForeColor.Equals(myLabelBackColor) Then
myLabelForeColor = HoldForeColor
Else
myLabelForeColor = myLabelBackColor
End If

Refresh()

If myFlashTime = myFlashOffTime Then
myFlashTime = myFlashOnTime
If Not Flasher Is Nothing Then Flasher.Change(myFlashTime,
myFlashOffTime)
Else
myFlashTime = myFlashOffTime
If Not Flasher Is Nothing Then Flasher.Change(myFlashTime,
myFlashOnTime)
End If

End Sub

#End Region 'Flash
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top