按方向键木有用,光标在按钮或option上移动,求教怎么破
代码如下:
Option Explicit
Dim a As Long
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 40 Then
a = 4
End If
If KeyCode = 38 Then
a = 3
End If
If KeyCode = 37 Then
a = 2
End If
If KeyCode = 39 Then
a = 1
End If
End Sub
Private Sub Option1_Click()
Timer1.Interval = 150
End Sub
Private Sub Option2_Click()
Timer1.Interval = 50
End Sub
Private Sub Option3_Click()
Timer1.Interval = 10
End Sub
Private Sub Timer1_Timer()
If a = 1 Then
Label1.Left = Label1.Left + 100 '右
End If
If a = 2 Then
Label1.Left = Label1.Left - 100 '左
End If
If a = 3 Then
Label1.Top = Label1.Top + 100 '上
End If
If a = 4 Then
Label1.Top = Label1.Top - 100 '下
End If
If Label1.Top < 0 Or Label1.Top > Frame1.Height Or Label1.Left < 0 Or Label1.Left > Frame1.Width Then
Timer1.Enabled = False: MsgBox "游戏失败", , "提示"
End If
If Label1.Top = Label1.Top + 500 Or Label1.Top = Label1.Top - 500 Or Label1.Left = Label1.Left + 500 Or Label1.Left = Label1.Left - 500 Then
Label3.Caption = Label3.Caption + 5
End If
End Sub
代码如下:
Option Explicit
Dim a As Long
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 40 Then
a = 4
End If
If KeyCode = 38 Then
a = 3
End If
If KeyCode = 37 Then
a = 2
End If
If KeyCode = 39 Then
a = 1
End If
End Sub
Private Sub Option1_Click()
Timer1.Interval = 150
End Sub
Private Sub Option2_Click()
Timer1.Interval = 50
End Sub
Private Sub Option3_Click()
Timer1.Interval = 10
End Sub
Private Sub Timer1_Timer()
If a = 1 Then
Label1.Left = Label1.Left + 100 '右
End If
If a = 2 Then
Label1.Left = Label1.Left - 100 '左
End If
If a = 3 Then
Label1.Top = Label1.Top + 100 '上
End If
If a = 4 Then
Label1.Top = Label1.Top - 100 '下
End If
If Label1.Top < 0 Or Label1.Top > Frame1.Height Or Label1.Left < 0 Or Label1.Left > Frame1.Width Then
Timer1.Enabled = False: MsgBox "游戏失败", , "提示"
End If
If Label1.Top = Label1.Top + 500 Or Label1.Top = Label1.Top - 500 Or Label1.Left = Label1.Left + 500 Or Label1.Left = Label1.Left - 500 Then
Label3.Caption = Label3.Caption + 5
End If
End Sub
