VB 用KeyAscii怎么实现按下方向键的
发布网友
发布时间:2024-10-15 17:15
我来回答
共4个回答
热心网友
时间:2024-11-05 18:12
If KeyAscii = 39 Then ‘vbKeyRight,代码39
热心网友
时间:2024-11-05 18:10
右键没有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
热心网友
时间:2024-11-05 18:11
好像你说的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
热心网友
时间:2024-11-05 18:09
非字符键按下时并不触发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