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

flashing button

hello,
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"
        Else
            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?
0
aplelois
Asked:
aplelois
1 Solution
 
VultenCommented:
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
        Else
            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)
0
 
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)
0
 
arif_eqbalCommented:
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
Else
     If Pos > Str.Length Then Pos = 0
     Button1.Text=Str.SubString(0,Pos)
     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"
Else
   Button1.text=""
End If
0

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