- 生肖
- 猴
- 星座
- 处女座
- 性别
- 男
- 积分
- 680
- 积分
- 1161
- 精华
- 1
- 阅读权限
- 70
- 注册时间
- 2012-5-3
- 最后登录
- 2016-9-22
- 帖子
- 136
- 生肖
- 猴
- 星座
- 处女座
- 性别
- 男
|
本帖最后由 sky_yx 于 2015-12-30 14:21 编辑
Dim mkey() As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If UBound ...[/quote]
我加了个timer 可以实现我的要求了 不过感觉不太好 再求更简单有效的方法- Dim mkey() As Integer
- Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
- If UBound(mkey) = 0 Then GoTo l
- If mkey(UBound(mkey) - 1) <> KeyCode Then
- l:
- mkey(UBound(mkey)) = KeyCode
- ReDim Preserve mkey(UBound(mkey) + 1) As Integer
- mkey(UBound(mkey)) = 0
- End If
-
- '我一开始移动的代码放在这里的 但是有点问题 上面说过了 所以我的方法是
- '放在timer里面 求更好的方法
-
- 'For i = 0 To UBound(mkey)
- 'If mkey(i) = 37 Then c1.Left = c1.Left - 20
- 'If mkey(i) = 40 Then c1.Top = c1.Top + 20
- 'If mkey(i) = 39 Then c1.Left = c1.Left + 20
- 'If mkey(i) = 38 Then c1.Top = c1.Top - 20
- 'Next i
- Dim aaa As String
- For i = 0 To UBound(mkey)
- aaa = aaa & mkey(i) & " | "
- Next
- Debug.Print aaa
- Form1.Cls
- Print aaa
-
- End Sub
- Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
- For i = 0 To UBound(mkey) - 1
- If mkey(i) = KeyCode Then
- If UBound(mkey) = 1 Or UBound(mkey) = 0 Then
- ReDim mkey(0) As Integer
- mkey(0) = 0
- Else
- For a = i To UBound(mkey) - 1
-
- mkey(a) = mkey(a + 1)
-
- Next a
- ReDim Preserve mkey(UBound(mkey) - 1) As Integer
-
- Dim bbb As String
- For n = 0 To UBound(mkey)
- bbb = bbb & mkey(n) & " | "
- Next
- Print bbb
-
- End If
- End If
- Next i
- End Sub
- Private Sub Form_Load()
- ReDim mkey(0) As Integer
- Timer1.Enabled = True
- Timer1.Interval = 33
- End Sub
- Private Sub Timer1_Timer()
- For i = 0 To UBound(mkey)
- If mkey(i) = 37 Then c1.Left = c1.Left - 20
- If mkey(i) = 40 Then c1.Top = c1.Top + 20
- If mkey(i) = 39 Then c1.Left = c1.Left + 20
- If mkey(i) = 38 Then c1.Top = c1.Top - 20
- Next i
- End Sub
复制代码
|
|