我想知道是否有一种方法可以通过向左,向右,向上和向下分配箭头键来围绕用户窗体移动图像。
我也看到很多线程提到将keypreview设置为true。这仅仅是UserForm1.keypreview = true的问题,这行代码应该放在哪里?
我到目前为止的代码如下。任何建议将不胜感激。
Private Sub Image1_KeyDown(KeyCode As Integer, Shift As Integer)
UserForm1.keypreview = True
Const NUDGE = 100
Select Case KeyCode
Case vbKeyRight
If Image1.Left + Image.Width + NUDGE >= UserForm1.ScaleWidth Then
Image.Left = UserForm1.ScaleWidth - Image1.Width
Beep
Else
Image1.Left = Image1.Left + NUDGE
End If
Case vbKeyLeft
If Image1.Left - NUDGE <= o Then
Image1.Left = 0
Beep
Else
Image1.Left = Image1.Left - NUDGE
End If
Case vbKeyUp
If Image1.Top - NUDGE <= 0 Then
Beep
Image1.Top = 0
Else
Image1.Top = Image1.Top - NUDGE
End If
Case vbKeyDown
If Image1.Top + Image1.Height + NUDGE >= UserForm1.ScaleHeight Then
Beep
Image1.Top = UserForm1.ScaleHeight - Image1.Height
Else
Image1.Top = Image1.Top + NUDGE
End If
End Select
End Sub