• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

flashing button

I have this button

    Private Sub cmdBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBrowse.Click
        If cmdBrowse.Text = "Start Browsing" Then
            Timer2.Enabled = True
            cmdBrowse.Text = "Stop Browsing"
            Timer2.Enabled = False
            cmdBrowse.Text = "Start Browsing"
        End If
    End Sub

I want something different for the button instead of changing to (Stop Browsing)
I would like the button to flash every 1 second
(Stop Browsing)
(Stop Browsing)
how can I do this?
1 Solution
Simple way is Create a form and add these as global variables

  Private WithEvents m_TimerFlash As New Timer
    Private m_Bool As Boolean = False

Add two buttons and use this code...

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        m_TimerFlash.Interval = 500
        m_TimerFlash.Enabled = Not m_TimerFlash.Enabled
    End Sub

    Private Sub m_TimerFlash_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles m_TimerFlash.Tick
        If m_Bool Then
            Button2.BackColor = Color.Navy
            Button2.BackColor = Color.LightGray
        End If
        m_Bool = Not m_Bool
    End Sub

And if your other Timer2 locks the thread... Add

Application.DoEvents somewhere in the code (will make other events fire even if its still browsning)
apleloisAuthor Commented:
no I dont want colors, what im looking for is something that changes the text of the button and looks like flashing..

-> (Stop Browsing)
-> (---)
-> (---------)
-> (---------------)
-> (Stop Browsing)
OK try something Like this

Dim Str as String = "Stop Browsing "
Dim Pos as Integer = 0

Set the Timer Interval to say 200, Then on Timer Tick

If Pos=Str.Length Then
     Pos +=1
     If Pos > Str.Length Then Pos = 0
     Pos +=1
End If

Or Something as simple as this
Dim ShowText As boolean

then on Timer Tick

ShowText = Not ShowText
if ShowText Then
   Button1.Text = "Stop Browsing"
End If

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now