# SetRect Function

`Declare Function SetRect Lib "user32.dll" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long`

SetRect sets the position and size of a rectangle. The two coordinates specified are the upper-left and lower-right corners of the rectangle. The function returns 0 if an error occured, or a non-zero value if successful.

lpRect
  The rectangle to set the position and size of.
X1
  The x coordinate of the upper-left corner of the rectangle.
Y1
  The y coordinate of the upper-left corner of the rectangle.
X2
  The x coordinate of the lower-right corner of the rectangle.
Y2
  The y coordinate of the lower-right corner of the rectangle.

Example:

    ' Set the position of rectangle r
    ' (This could also be done by setting its .Left, .Top, etc. values manually)
    Dim r As RECT
    x = SetRect(r, 50, 20, 100, 70)  ' r = (50,20)-(100,70)

Related Call: SetRectEmpty
Category: Rectangles
Back to the index.