# Simple Drag operation

**URL:** <https://ifnotnil.com/t/simple-drag-operation/2291>\
**Category:** Other\
**Created:** [30 December 2021 18:29 UTC](https://ifnotnil.com/t/simple-drag-operation/2291 "2021-12-30T18:29:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaveS](https://ifnotnil.com/user_avatar/ifnotnil.com/daves/32/79_2.png) [@DaveS](https://ifnotnil.com/u/DaveS)\
**Post date:** [30 December 2021 18:29 UTC](https://ifnotnil.com/t/simple-drag-operation/2291/1 "2021-12-30T18:29:08Z")

</div>

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?

```auto
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

---

<div class="post-metadata">

**Author:** ![anon72844311](https://ifnotnil.com/letter_avatar_proxy/v4/letter/a/9de0a6/32.png) [@anon72844311](https://ifnotnil.com/u/anon72844311)\
**Post date:** [30 December 2021 19:08 UTC](https://ifnotnil.com/t/simple-drag-operation/2291/2 "2021-12-30T19:08:31Z")

</div>

```auto
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
```

---

<div class="post-metadata">

**Author:** ![DaveS](https://ifnotnil.com/user_avatar/ifnotnil.com/daves/32/79_2.png) [@DaveS](https://ifnotnil.com/u/DaveS)\
**Post date:** [30 December 2021 19:09 UTC](https://ifnotnil.com/t/simple-drag-operation/2291/3 "2021-12-30T19:09:50Z")

</div>

PERFECT! thanks
