esempio
codice:
Option Explicit
Dim lim_up, lim_down, lim_left, lim_right As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyUp
If Shape1.Top <= lim_up Then Exit Sub
Shape1.Top = Shape1.Top - 10
Case vbKeyDown
If Shape1.Top >= lim_down - Shape1.Height Then Exit Sub
Shape1.Top = Shape1.Top + 10
Case vbKeyLeft
If Shape1.Left <= lim_left Then Exit Sub
Shape1.Left = Shape1.Left - 10
Case vbKeyRight
If Shape1.Left >= lim_right - Shape1.Width Then Exit Sub
Shape1.Left = Shape1.Left + 10
End Select
End Sub
Private Sub Form_Load()
lim_up = Line1.Y1
lim_down = Line2.Y1
lim_left = Line3.X1
lim_right = Line4.X1
End Sub