我在程序里编写了倒计时的程序代码。当倒计时结束时触发某一动作。我现在想实现,在倒计时的过程中任何的键盘操作都会终止倒计时。我该怎么实现。窗体上有几个command_button。我编写键盘事件的时候当按下上下左右键时只是焦点在案件中切换并不会出发键盘事件。怎么办呢。谢谢。。下面是我的倒计时代码。。
Dim s As IntegerPrivate Sub Form_Load()
Me.KeyPreview = True
Timer1.Interval = 1000
s = 5
End SubPrivate Sub Timer1_Timer()
s = s - 1
Label1.Caption = "还有" & s & "秒启动"
If s = 0# Then
Label1.Caption = ""
Timer1.Enabled = False
End If
End Sub
Dim s As IntegerPrivate Sub Form_Load()
Me.KeyPreview = True
Timer1.Interval = 1000
s = 5
End SubPrivate Sub Timer1_Timer()
s = s - 1
Label1.Caption = "还有" & s & "秒启动"
If s = 0# Then
Label1.Caption = ""
Timer1.Enabled = False
End If
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 39 Then
Label1.Caption = ""
Timer1.Enabled = False
End If
End Sub
If KeyCode = 39 Then
Label1.Caption = ""
Timer1.Enabled = False
DoEvents
End If
End Sub
Private Sub cmdStart_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 39 Then
Label1.Caption = ""
Timer1.Enabled = False
End If
End Sub