VB做一个键盘控制小球移动的问题
用VB做一个小球移动的问题,代码是:SubForm_KeyDown(keycodeAsInteger,shiftAsInteger)SelectCasekeycodeCa...
用VB做一个小球移动的问题,代码是:
Sub Form_KeyDown(keycode As Integer, shift As Integer)
Select Case keycode
Case vbKeyUp: Shape1.Move Shape1.Left, Shape1.Top - 100
Case vbKeyDown: Shape1.Move Shape1.Left, Shape1.Top + 100
Case vbKeyLeft: Shape1.Move Shape1.Left - 100, Shape1.Top
Case vbKeyRight: Shape1.Move Shape1.Left + 100, Shape1.Top
Case vbKeyUp And vbKeyLeft: Shape1.Move Shape1.Left - 100, Shape1.Top - 100
Case vbKeyUp And vbKeyRight: Shape1.Move Shape1.Left + 100, Shape1.Top - 100
Case vbKeyDown And vbKeyLeft: Shape1.Move Shape1.Left - 100, Shape1.Top + 100
Case vbKeyDown And vbKeyRight: Shape1.Move Shape1.Left + 100, Shape1.Top + 100
End Select
End Sub
怎样才能限制小球移动的区域?
顺便还问下,这个程序控制小球斜着走必须两个方向键同时按下去才可以,怎样才能优化成不管同不同时按下两个键就可以斜着走呢?
可以具体一点吗? 不要用小键盘,能不能用光标键组合做到呢? 展开
Sub Form_KeyDown(keycode As Integer, shift As Integer)
Select Case keycode
Case vbKeyUp: Shape1.Move Shape1.Left, Shape1.Top - 100
Case vbKeyDown: Shape1.Move Shape1.Left, Shape1.Top + 100
Case vbKeyLeft: Shape1.Move Shape1.Left - 100, Shape1.Top
Case vbKeyRight: Shape1.Move Shape1.Left + 100, Shape1.Top
Case vbKeyUp And vbKeyLeft: Shape1.Move Shape1.Left - 100, Shape1.Top - 100
Case vbKeyUp And vbKeyRight: Shape1.Move Shape1.Left + 100, Shape1.Top - 100
Case vbKeyDown And vbKeyLeft: Shape1.Move Shape1.Left - 100, Shape1.Top + 100
Case vbKeyDown And vbKeyRight: Shape1.Move Shape1.Left + 100, Shape1.Top + 100
End Select
End Sub
怎样才能限制小球移动的区域?
顺便还问下,这个程序控制小球斜着走必须两个方向键同时按下去才可以,怎样才能优化成不管同不同时按下两个键就可以斜着走呢?
可以具体一点吗? 不要用小键盘,能不能用光标键组合做到呢? 展开
2个回答
展开全部
建议你用键盘右边的数字键盘控制(7,9,1,3分别代表左上,右上,左下,右下)代码如下:
Sub Form_KeyDown(keycode As Integer, shift As Integer)
Select Case keycode
Case vbKeyUp: Shape1.Move Shape1.Left, Shape1.Top - 100
Case vbKeyDown: Shape1.Move Shape1.Left, Shape1.Top + 100
Case vbKeyLeft: Shape1.Move Shape1.Left - 100, Shape1.Top
Case vbKeyRight: Shape1.Move Shape1.Left + 100, Shape1.Top
Case 103: Shape1.Move Shape1.Left - 100, Shape1.Top - 100
Case 105: Shape1.Move Shape1.Left + 100, Shape1.Top - 100
Case 97: Shape1.Move Shape1.Left - 100, Shape1.Top + 100
Case 99: Shape1.Move Shape1.Left + 100, Shape1.Top + 100
End Select
End Sub
Sub Form_KeyDown(keycode As Integer, shift As Integer)
Select Case keycode
Case vbKeyUp: Shape1.Move Shape1.Left, Shape1.Top - 100
Case vbKeyDown: Shape1.Move Shape1.Left, Shape1.Top + 100
Case vbKeyLeft: Shape1.Move Shape1.Left - 100, Shape1.Top
Case vbKeyRight: Shape1.Move Shape1.Left + 100, Shape1.Top
Case 103: Shape1.Move Shape1.Left - 100, Shape1.Top - 100
Case 105: Shape1.Move Shape1.Left + 100, Shape1.Top - 100
Case 97: Shape1.Move Shape1.Left - 100, Shape1.Top + 100
Case 99: Shape1.Move Shape1.Left + 100, Shape1.Top + 100
End Select
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询