How to Move Canvas Object at range boundary?

I want to be able to move an object at x and y/top and Left following the mouse pointer, however, I need the object to stop moving at x=400, y=400 and x=0, y=0. How would be able to achieve this?

just limit the input
if x > 400 then x=400
if x< 0 then x = 0

Is that how sliders or scrollbars work when dragging?

scrollbars have a value range yes
but i guess you will move a image object in canvas free with the mouse pointer over it.
with the title “Move Canvas Object at range boundary?” i understand you try to move a canvas ui control around in a window. regular i would use a static canvas as viewport and drawing shapes in it.

thank you, Markus

How to Scroll an Image Inside of a Canvas? - General - Xojo Programming Forum

have a look in graphics and multimedia examples.