VB 用KeyAscii怎么实现按下方向键的
PrivateSubForm_Load()Form1.KeyPreview=TrueEndSubPrivateSubForm_KeyPress(KeyAscii%)IfK...
Private Sub Form_Load()
Form1.KeyPreview = True
End Sub
Private Sub Form_KeyPress(KeyAscii%)
If KeyAscii = Asc("39") Then ‘vbKeyRight,代码39
Picture1.Left = Picture1.Left + 50
End If
End Sub
为什么这么写按下方向键右键的时候图片不会移动,应该怎么修改。 展开
Form1.KeyPreview = True
End Sub
Private Sub Form_KeyPress(KeyAscii%)
If KeyAscii = Asc("39") Then ‘vbKeyRight,代码39
Picture1.Left = Picture1.Left + 50
End If
End Sub
为什么这么写按下方向键右键的时候图片不会移动,应该怎么修改。 展开
4个回答
展开全部
好像你说的vbkeyright的代码39是keycode而不是ascii码,你可以用form_keydown判断
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 39 Then
Picture1.Left = Picture1.Left + 50
End If
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 39 Then
Picture1.Left = Picture1.Left + 50
End If
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
非字符键按下时并不触发keypress事件,只触发keyup,keydown事件。下面代码经测试可行。
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Right Then
RichTextBox1.Location = New Point(RichTextBox1.Location.X + 20, RichTextBox1.Location.Y)
End If
End Sub
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Right Then
RichTextBox1.Location = New Point(RichTextBox1.Location.X + 20, RichTextBox1.Location.Y)
End If
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
右键没有ASCI码,你按照我下面这段代码的写法写一下。是可以的。Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyLeft
Label1.Left = Label1.Left - 10
Case vbKeyRight
Label1.Left = Label1.Left + 10
Case vbKeyUp
Label1.Top = Label1.Top - 10
Case vbKeyDown
Label1.Top = Label1.Top + 10
Case Else
End Select
End Sub
Select Case KeyCode
Case vbKeyLeft
Label1.Left = Label1.Left - 10
Case vbKeyRight
Label1.Left = Label1.Left + 10
Case vbKeyUp
Label1.Top = Label1.Top - 10
Case vbKeyDown
Label1.Top = Label1.Top + 10
Case Else
End Select
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
If KeyAscii = 39 Then ‘vbKeyRight,代码39
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询