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 myLabelForeColo r value.)
#Region "Flash"
Private myFlashTime As Long
Private Flasher As System.Threadin g.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 = myLabelForeColo r
Flasher = New System.Threadin g.Timer(Address Of Flash, Nothing,
myFlashWaitTime , myFlashOnTime)
End Sub
Public Sub StopFlashing()
If Flasher Is Nothing Then Exit Sub
Flasher.Change( System.Threadin g.Timeout.Infin ite, 0)
Flasher = Nothing
Me.myLabelForeC olor = 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 myLabelForeColo r.Equals(myLabe lBackColor) Then
myLabelForeColo r = HoldForeColor
Else
myLabelForeColo r = myLabelBackColo r
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
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!