This happens only with MouseMove and MouseUp on the desktop.
If you want to avoid getting values from outsides you must check if x and y are insides the form limits.
If x >=0 and x<= Form.Width and y>= 0 and y<=Form.Height Then
Be aware that there is also a difference in the behaviour of the MouseMove event between the desktop and the device. On the desktop the MousMove event is fired even without a MouseDown event, on the device the MouseMove event is only fired after a MouseDown event (the contact of the stylus is needed). To avoid this you should add a flag in the MousDown event, test it in the MouseMove event and set it back in the MousUp event:
Sub Form_MouseDown(x,y)
FlagMouse = 1
End Sub
Sub Form_MouseMove(x,y)
If FlagMouse = 1 Then
End If
End Sub
Sub Form_MouseUp(x,y)
FlagMouse = 0
End Sub
Best regards.