Realbasic.Point.Offset

From Xojo Documentation

Method

Realbasic.Point.Offset(DeltaX As Integer, DeltaY As Integer)

New in 2011r2

Supported for all project types and targets.

Moves the point the given number of pixels. Positive numbers move the point down or to the right, negative move it up or to the left.

Sample Code

This example is in the MouseDrag event of a Rect. The object is being cloned as the way to update its position. MouseOffset is a Point property of the window.

// Update our mouse position.
mouseposition = New Realbasic.Point(x, y)

// If we're actually dragging something, move the rect.
// We update the rect's origin with a CLONE of the mouse position,
// because MousePosition is an instance of the REALbasic.Point class.
// Without the clone, when we call the offset function, we'll also update
// the MousePosition property, since both DraggingRect.Origin and MousePosition
// would point to the same variable.

// The offset function simply shifts the rect. Positive for right/down,
// negative for left/up.

If draggingrect <> Nil Then
draggingrect.Origin = mouseposition.Clone
draggingrect.Offset(mouseoffset.X, mouseoffset.Y)
End If

// refresh, without erasing the background
Me.Invalidate(False)