Simple Drag operation

This is for Xojo, but will be translated to Swift once I get it to work.

I have a canvas on the screen, the I wish to drag around.
Shouldn’t this work?

Function MouseDown(X As Integer, Y As Integer) Handles MouseDown as Boolean
  // get the distance the mouse is from the corner of the canvas
  mdx = Me.Left-x
  mdy = Me.top-y
  Return True
End Function

Sub MouseDrag(X As Integer, Y As Integer) Handles MouseDrag
  // move canvas to new location
  Me.Left=(x-mdx)
  Me.top =(y-mdy)
End Sub

if kinda moves it, flashing and jumping around and sometimes not moving at all

Function MouseDown(x As Integer, y As Integer) Handles MouseDown as Boolean
  // get the distance the mouse is from the corner of the canvas
  mdx = x
  mdy = y
  Return True
End Function

Sub MouseDrag(x As Integer, y As Integer) Handles MouseDrag
  // move canvas to new location
  Me.Left = Me.Left + x - mdx
  Me.Top = Me.Top + y - mdy
End Sub

PERFECT! thanks