button flash with red and white color

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, All,

how to flash button with 2 color( eg. red and white)? then when user click
button, the button stop flash and stay red color?

Thanks
 
martin1 said:
how to flash button with 2 color( eg. red and white)? then when user click
button, the button stop flash and stay red color?

You may want to use a timer component ('System.Windows.Forms.Timer') and use
the timer to set the button control's 'BackColor' property to the desired
color.
 
Private ButtonColor As System.Drawing.Color
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
If ButtonColor = Color.Red Then
ButtonColor = Color.White

Else
ButtonColor = Color.Red
End If
Me.Button1.BackColor = ButtonColor
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

ButtonColor = Color.Red
Me.Button1.BackColor = ButtonColor
Me.Timer1.Interval = 1000 ' 1 sec
Me.Timer1.Start()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Timer1.Stop()
ButtonColor = Color.Red
Me.Button1.BackColor = ButtonColor
End Sub

I tried it in VS 2005.
 
Thank you. Ahmed,

The code i wrote works also:

Dim aTimer As New System.Timers.Timer()
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
'Set the Interval to 1 seconds.
aTimer.Interval = 1000
aTimer.Enabled = True
ButtonI.BackColor = Color.Red
Else
ButtonI.BackColor = Color.White
End If
End Sub
Private Sub OnTimedEvent(ByVal source As Object, ByVal e As
ElapsedEventArgs)
'test button flash
If (ButtonI.BackColor = Color.Red) Then
ButtonI.BackColor = Color.White
ElseIf (ButtonI.BackColor = Color.White) Then
ButtonI.BackColor = Color.Red
End If
End Sub
 
You're welcome :D
Thank you. Ahmed,

The code i wrote works also:

Dim aTimer As New System.Timers.Timer()
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
'Set the Interval to 1 seconds.
aTimer.Interval = 1000
aTimer.Enabled = True
ButtonI.BackColor = Color.Red
Else
ButtonI.BackColor = Color.White
End If
End Sub
Private Sub OnTimedEvent(ByVal source As Object, ByVal e As
ElapsedEventArgs)
'test button flash
If (ButtonI.BackColor = Color.Red) Then
ButtonI.BackColor = Color.White
ElseIf (ButtonI.BackColor = Color.White) Then
ButtonI.BackColor = Color.Red
End If
End Sub
 
Hi, Ahmed,

when run yuor code, get error messgae "Handles clause requires a WithEvents
variable defined in the containing type or one of its base types " from
Timer1 below. Any clue?

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
 
You need to add a timer component to the form.
Hi, Ahmed,

when run yuor code, get error messgae "Handles clause requires a WithEvents
variable defined in the containing type or one of its base types " from
Timer1 below. Any clue?

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
 
If you are using visual studio, you open your toobox and drag and drop
a timer component to the form. If your writing code in notepad, you
need the following code:

Friend WithEvents Timer1 As System.Timers.Timer

Me.Timer1 = New System.Timers.Timer ' in your constructor
 
Back
Top