Public Shared Sub MoveControl(ByVal C As Control, ByVal X As Integer, ByVal Y As Integer)
If C.Parent Is Nothing Then Throw New Exception("It has no parent.")
Dim NewBounds As New Rectangle(C.Left + X, C.Top + Y, C.Width, C.Height)
If C.Parent.ClientRectangle.Contains(NewBounds) Then C.Bounds = NewBounds
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.Up : MoveControl(Me.PictureBox1, 0, -5)
Case Keys.Down : MoveControl(Me.PictureBox1, 0, 5)
Case Keys.Left : MoveControl(Me.PictureBox1, -5, 0)
Case Keys.Right : MoveControl(Me.PictureBox1, 5, 0)
End Select
End Sub