我想问一下 是不是form的keydown事件会影响到picture1的keydown时间 谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/27 06:22:09
我想问一下 是不是form的keydown事件会影响到picture1的keydown时间 谢谢
Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 37 Then

Picture2.BackColor = vbGreen
End If
End Sub

Private Sub Picture2_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 39 Then
Picture1.BackColor = vbGreen
End If
End Sub
为什么我按下keycode为37的键 picture2变为绿色的
但是我再按下keycode为39的键picture1不变色

那是因为picture2一直没有得到焦点,

可以用picture2.setfocus

试试我改过的代码:
Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 37 Then
Picture2.BackColor = vbGreen
Picture2.SetFocus'************
End If
End Sub

Private Sub Picture2_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 39 Then
Picture1.BackColor = vbGreen
End If
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Print "form"
End Sub

Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)
Print "pic"
End Sub