Home All Groups Group Topic Archive Search About

button flash with red and white color

Author
26 Jun 2006 6:22 PM
martin1
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

Author
26 Jun 2006 7:40 PM
Herfried K. Wagner [MVP]
"martin1" <mart***@discussions.microsoft.com> schrieb:
> 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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
26 Jun 2006 7:50 PM
martin1
I tried and it doesn't work,  any sample code? Thanks

Show quoteHide quote
"Herfried K. Wagner [MVP]" wrote:

> "martin1" <mart***@discussions.microsoft.com> schrieb:
> > 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.
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
>
Author
27 Jun 2006 2:44 AM
Ahmed
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.

Ahmed
martin1 wrote:
Show quoteHide quote
> I tried and it doesn't work,  any sample code? Thanks
>
> "Herfried K. Wagner [MVP]" wrote:
>
> > "martin1" <mart***@discussions.microsoft.com> schrieb:
> > > 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.
> >
> > --
> >  M S   Herfried K. Wagner
> > M V P  <URL:http://dotnet.mvps.org/>
> >  V B   <URL:http://classicvb.org/petition/>
> >
> >
Author
27 Jun 2006 1:36 PM
martin1
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

Show quoteHide quote
"Ahmed" wrote:

>  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.
>
> Ahmed
> martin1 wrote:
> > I tried and it doesn't work,  any sample code? Thanks
> >
> > "Herfried K. Wagner [MVP]" wrote:
> >
> > > "martin1" <mart***@discussions.microsoft.com> schrieb:
> > > > 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.
> > >
> > > --
> > >  M S   Herfried K. Wagner
> > > M V P  <URL:http://dotnet.mvps.org/>
> > >  V B   <URL:http://classicvb.org/petition/>
> > >
> > >
>
>
Author
27 Jun 2006 2:37 PM
Ahmed
You're welcome :D

martin1 wrote:
Show quoteHide quote
> 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
>
> "Ahmed" wrote:
>
> >  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.
> >
> > Ahmed
> > martin1 wrote:
> > > I tried and it doesn't work,  any sample code? Thanks
> > >
> > > "Herfried K. Wagner [MVP]" wrote:
> > >
> > > > "martin1" <mart***@discussions.microsoft.com> schrieb:
> > > > > 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.
> > > >
> > > > --
> > > >  M S   Herfried K. Wagner
> > > > M V P  <URL:http://dotnet.mvps.org/>
> > > >  V B   <URL:http://classicvb.org/petition/>
> > > >
> > > >
> >
> >
Author
27 Jun 2006 10:06 PM
martin1
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

Show quoteHide quote
"Ahmed" wrote:

>  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.
>
> Ahmed
> martin1 wrote:
> > I tried and it doesn't work,  any sample code? Thanks
> >
> > "Herfried K. Wagner [MVP]" wrote:
> >
> > > "martin1" <mart***@discussions.microsoft.com> schrieb:
> > > > 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.
> > >
> > > --
> > >  M S   Herfried K. Wagner
> > > M V P  <URL:http://dotnet.mvps.org/>
> > >  V B   <URL:http://classicvb.org/petition/>
> > >
> > >
>
>
Author
27 Jun 2006 10:28 PM
Ahmed
You need to add a timer component to the form.

martin1 wrote:
Show quoteHide quote
> 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
>
> "Ahmed" wrote:
>
> >  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.
> >
> > Ahmed
> > martin1 wrote:
> > > I tried and it doesn't work,  any sample code? Thanks
> > >
> > > "Herfried K. Wagner [MVP]" wrote:
> > >
> > > > "martin1" <mart***@discussions.microsoft.com> schrieb:
> > > > > 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.
> > > >
> > > > --
> > > >  M S   Herfried K. Wagner
> > > > M V P  <URL:http://dotnet.mvps.org/>
> > > >  V B   <URL:http://classicvb.org/petition/>
> > > >
> > > >
> >
> >
Author
28 Jun 2006 12:55 PM
martin1
is this import correct to add Timer component?
Imports System.Timers

Show quoteHide quote
"Ahmed" wrote:

> You need to add a timer component to the form.
>
> martin1 wrote:
> > 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
> >
> > "Ahmed" wrote:
> >
> > >  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.
> > >
> > > Ahmed
> > > martin1 wrote:
> > > > I tried and it doesn't work,  any sample code? Thanks
> > > >
> > > > "Herfried K. Wagner [MVP]" wrote:
> > > >
> > > > > "martin1" <mart***@discussions.microsoft.com> schrieb:
> > > > > > 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.
> > > > >
> > > > > --
> > > > >  M S   Herfried K. Wagner
> > > > > M V P  <URL:http://dotnet.mvps.org/>
> > > > >  V B   <URL:http://classicvb.org/petition/>
> > > > >
> > > > >
> > >
> > >
>
>
Author
28 Jun 2006 1:42 PM
Ahmed
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

martin1 wrote:
Show quoteHide quote
> is this import correct to add Timer component?
> Imports System.Timers
>
> "Ahmed" wrote:
>
> > You need to add a timer component to the form.
> >
> > martin1 wrote:
> > > 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
> > >
> > > "Ahmed" wrote:
> > >
> > > >  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.
> > > >
> > > > Ahmed
> > > > martin1 wrote:
> > > > > I tried and it doesn't work,  any sample code? Thanks
> > > > >
> > > > > "Herfried K. Wagner [MVP]" wrote:
> > > > >
> > > > > > "martin1" <mart***@discussions.microsoft.com> schrieb:
> > > > > > > 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.
> > > > > >
> > > > > > --
> > > > > >  M S   Herfried K. Wagner
> > > > > > M V P  <URL:http://dotnet.mvps.org/>
> > > > > >  V B   <URL:http://classicvb.org/petition/>
> > > > > >
> > > > > >
> > > >
> > > >
> >
> >