VB 图片框的上下左右移动问题!
我想用方向键控制图片在图片框中移动,这个代码怎么实现不到啊!PrivateSubForm_KeyPress(KeyAsciiAsInteger)IfKeyAscii=vb...
我想用方向键控制图片在 图片框中移动,这个代码怎么实现不到啊!
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyUp Then
Img1.Top = Img1.Top - 35
End If
If KeyAscii = vbKeyLeft Then
Img1.Left = Img1.Left - 35
End If
End Sub
(这是上和左的代码。怎么运行后按键没反映啊?)
KeyPress 事件不行吗??? (图片框:Pic1 图像框是:Img1) 展开
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyUp Then
Img1.Top = Img1.Top - 35
End If
If KeyAscii = vbKeyLeft Then
Img1.Left = Img1.Left - 35
End If
End Sub
(这是上和左的代码。怎么运行后按键没反映啊?)
KeyPress 事件不行吗??? (图片框:Pic1 图像框是:Img1) 展开
展开全部
参数错误不是KeyAscii而是KeyCode,另外你的接收对象你不对是Picture1(我这里使用的picturebox,你可以自己改一下),不是Form。事件是KeyDown
下面改一下,你看看吧
Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then
Picture1.Top = Picture1.Top - 35
End If
If KeyCode = vbKeyLeft Then
Picture1.Left = Picture1.Left - 35
End If
End Sub
下面改一下,你看看吧
Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then
Picture1.Top = Picture1.Top - 35
End If
If KeyCode = vbKeyLeft Then
Picture1.Left = Picture1.Left - 35
End If
End Sub
展开全部
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then '上
Img1.Top = Img1.Top - 35
End If
If KeyCode = vbKeyDown Then '下
Img1.Top = Img1.Top + 35
End If
If KeyCode = vbKeyLeft Then '左
Img1.Left = Img1.Left - 35
End If
If KeyCode = vbKeyRight Then '右
Img1.Left = Img1.Left + 35
End If
End Sub
If KeyCode = vbKeyUp Then '上
Img1.Top = Img1.Top - 35
End If
If KeyCode = vbKeyDown Then '下
Img1.Top = Img1.Top + 35
End If
If KeyCode = vbKeyLeft Then '左
Img1.Left = Img1.Left - 35
End If
If KeyCode = vbKeyRight Then '右
Img1.Left = Img1.Left + 35
End If
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在窗体的keyascii事件中判断键值
当是方向键时移动图片框
当是方向键时移动图片框
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询