vb怎么让两个shape同时受键盘控制移动?本人新手(●'◡'●) 现在shape1和shape2只能一个一个动
代码如下PrivateSubform_KeyDown(KeyCodeAsInteger,ShiftAsInteger)WithShape1SelectCaseKeyCod...
代码如下
Private Sub form_KeyDown(KeyCode As Integer, Shift As Integer)
With Shape1
Select Case KeyCode
Case vbKeyLeft '左箭头键
.Left = .Left - 6 * Screen.TwipsPerPixelX
Case vbKeyUp '上箭头键
.Top = .Top - 6 * Screen.TwipsPerPixelY
Case vbKeyRight '右箭头键
.Left = .Left + 6 * Screen.TwipsPerPixelX
Case vbKeyDown '下箭头键
.Top = .Top + 6 * Screen.TwipsPerPixelY
End Select
End With
With Shape2
Select Case KeyCode
Case vbKeyA '左箭头键
.Left = .Left - 6 * Screen.TwipsPerPixelX
Case vbKeyW '上箭头键
.Top = .Top - 6 * Screen.TwipsPerPixelY
Case vbKeyD '右箭头键
.Left = .Left + 6 * Screen.TwipsPerPixelX
Case vbKeyS '下箭头键
.Top = .Top + 6 * Screen.TwipsPerPixelY
End Select
End With
End Sub 展开
Private Sub form_KeyDown(KeyCode As Integer, Shift As Integer)
With Shape1
Select Case KeyCode
Case vbKeyLeft '左箭头键
.Left = .Left - 6 * Screen.TwipsPerPixelX
Case vbKeyUp '上箭头键
.Top = .Top - 6 * Screen.TwipsPerPixelY
Case vbKeyRight '右箭头键
.Left = .Left + 6 * Screen.TwipsPerPixelX
Case vbKeyDown '下箭头键
.Top = .Top + 6 * Screen.TwipsPerPixelY
End Select
End With
With Shape2
Select Case KeyCode
Case vbKeyA '左箭头键
.Left = .Left - 6 * Screen.TwipsPerPixelX
Case vbKeyW '上箭头键
.Top = .Top - 6 * Screen.TwipsPerPixelY
Case vbKeyD '右箭头键
.Left = .Left + 6 * Screen.TwipsPerPixelX
Case vbKeyS '下箭头键
.Top = .Top + 6 * Screen.TwipsPerPixelY
End Select
End With
End Sub 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询