Using parts of the QDRegion class from the "REALbasic Tool Box" by Matthijs van Duin, available at <ftp://ftp.urcentral.com/pub/Users/mfwww/Tool_Box/Tool_Box_v1.sit>
What it is
DragInWindow is a module that provides a method for dragging RectControls within a given limiting area and optionally constrained to either vertical or horizontal movement.
It can be used to move divider bars inside windows or if you want a drag region to be moved only within a certain area of your window.
This module is free for you to use and to distribute.
How to use it
Drag the "DragInWndModule" and the "QDRegion" class to your project window.
Methods
DragInWindow(Rect as RectControl, LimitLeft as integer, LimitTop as integer, LimitRight as integer, LimitBottom as integer, Axis as integer)
This method is called to do the actual drag. Call it from the MouseDown event of any RectControl, e.g. a canvas or a placard.
The Rect parameter is the RectControl that is to be dragged. This would usually be 'me'. After the drag, the method automatically sets the control's new Left and Top properties.
The LimitLeft, LimitTop, LimitRight and LimitBottom parameters describe an imaginary rectangle which limits the area in which the control can be moved. If you wanted it to be moved only within the borders of your window, you'd pass 0, 0, self.width and self.height.
The Axis parameter is used to constrain the movement to either the horizontal or the vertical axis. It can have the following values:
0 - Don't constrain
1 - Constrain horizontally
2 - Constrain vertically
Properties
DragBorderThickness as integer
This property can be set to define the thickness of the border of the drag region. The default is 1. Set it before calling the DragInWindow method.
Note: Borders thicker than 4 pixels are drawn outlined.