- O -


OffsetRect Function

Declare Function OffsetRect Lib "user32.dll" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long

OffsetRect slides a RECT-type variable without changing its size. The rectangle is moved x pixels horizontally and y pixels vertically, while the size is preseved. If the value to slide is negative, it is moved left or up (depending on which direction it is), and positive moves to the right or down. Really, the x value is added to the .Left and .Right values, while y is added to the .Top and .Bottom values. You can safely ignore the value returned.
lpRectThe rectangle to slide.
xHow many pixels horizontally to move. Negative values move to the left, positive values move to the right.
yHow many pixels vertically to move. Negative values move up, positive values move down.
Example:
  'Move a rectangle 100 to the right and 25 up
  Dim r As RECT
  x = SetRect(r, 50, 50, 150, 150) 'API function sets the values of the rectangle
  '.Left = 50, .Top = 50, .Right = 100, .Bottom = 100
  x = OffsetRect(r, 100, -25)
  'Now, .Left = 150, .Top = 25, .Right = 200, .Bottom = 75


Related Call: InflateRect
Category: RECT Manipulation
Back to the index.


Home
Paul Kuliniewicz
E-mail: Borg953@aol.com
All material presented on these pages is Copyright © Paul Kuliniewicz, except for other copyrighted material.
http://members.aol.com/Borg953/api/o.html