T
Terry Brown
I am building a stopwatch which I want to start and stop by either
pressing a navigation button or an on-screen button. I update the timer
display by using a Timer with the interval set to 100 milliseconds
My code looks like this:
Private Sub Clock_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clock.Tick
If clock_enabled Then
QueryPerformanceCounter(ticker)
ClockButton.Text = MakeTimeString(ticker - startTicker)
End If
End Sub
Private Sub ClockButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClockButton.Click
If clock_enabled Then
clock_enabled = False
Clock.Enabled = False
Else
QueryPerformanceCounter(Form1.startTicker)
clock_enabled = True
Clock.Enabled = True
End If
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Dim str As String
'any of the navigation keys will start/stop the clock
If e.KeyCode = Keys.Up Or e.KeyCode = Keys.Down Or e.KeyCode = Keys.Left Or e.KeyCode = Keys.Right Then
If clock_enabled Then
clock_enabled = False
Clock.Enabled = False
Else
QueryPerformanceCounter(Form1.startTicker)
clock_enabled = True
Clock.Enabled = True
End If
End If
End Sub
The ClockButton_Click routine always works and behaves as I expect.
The Form1_KeyDown routine also works, but only if I don't cause
ClockButton_Click to be activated. I can press any of the navigation
buttons and the clock starts and stops as expected, but if I press the
ClockButton (the onscreen button) which causes ClockButton_Click to be
executed, then from that point on, Form1_KeyDown does not get executed
when I press a navigation button.
The reason I duplicate clock_enabled and Clock.Enabled is for ease of
information passing to other classes.
Anyone have an idea about what might be going on here??
thanks,
Terry Brown
Stickman Software
http://www.stickmansoftware.com
pressing a navigation button or an on-screen button. I update the timer
display by using a Timer with the interval set to 100 milliseconds
My code looks like this:
Private Sub Clock_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clock.Tick
If clock_enabled Then
QueryPerformanceCounter(ticker)
ClockButton.Text = MakeTimeString(ticker - startTicker)
End If
End Sub
Private Sub ClockButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClockButton.Click
If clock_enabled Then
clock_enabled = False
Clock.Enabled = False
Else
QueryPerformanceCounter(Form1.startTicker)
clock_enabled = True
Clock.Enabled = True
End If
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Dim str As String
'any of the navigation keys will start/stop the clock
If e.KeyCode = Keys.Up Or e.KeyCode = Keys.Down Or e.KeyCode = Keys.Left Or e.KeyCode = Keys.Right Then
If clock_enabled Then
clock_enabled = False
Clock.Enabled = False
Else
QueryPerformanceCounter(Form1.startTicker)
clock_enabled = True
Clock.Enabled = True
End If
End If
End Sub
The ClockButton_Click routine always works and behaves as I expect.
The Form1_KeyDown routine also works, but only if I don't cause
ClockButton_Click to be activated. I can press any of the navigation
buttons and the clock starts and stops as expected, but if I press the
ClockButton (the onscreen button) which causes ClockButton_Click to be
executed, then from that point on, Form1_KeyDown does not get executed
when I press a navigation button.
The reason I duplicate clock_enabled and Clock.Enabled is for ease of
information passing to other classes.
Anyone have an idea about what might be going on here??
thanks,
Terry Brown
Stickman Software
http://www.stickmansoftware.com