怎样才能在vb6中,用←↑→↓ 来控制image的位置?

来源:百度知道 编辑:UC知道 时间:2024/06/11 16:08:01
怎样才能在vb6中,用←↑→↓ 来控制image的位置?(加分的)
大家来看看 那里错了?
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 37 Then
P1.Left = P1.Left - 50
ElseIf keyasscii = 38 Then
P1.Top = P1.Top - 50
ElseIf keyasscii = 39 Then
P1.Left = P1.Left + 50
ElseIf keyasscii = 40 Then
P1.Top = P1.Top + 50
End If
End Sub

(p1就是picturebox)

首先你要将窗体的KEYPreView属性设置为TRUE
有些按钮不能在KEYPress事件里响应,
要在KEYUp响应
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 37 Then
P1.Left = P1.Left - 50
ElseIf KeyCode = 38 Then
P1.Top = P1.Top - 50
ElseIf KeyCode = 39 Then
P1.Left = P1.Left + 50
ElseIf KeyCode = 40 Then
P1.Top = P1.Top + 50
End If
End Sub
'这个调试OK