Description |
The Bounds function creates a TRect rectangle value from Top, Left coordinates, and Width, Height size values.
It provides a useful alternative to the Rect function, where you must know the bottom and right coordinates rather than the rectangle size.
|
| Related commands | Point | | Generates a TPoint value from X and Y values | PointsEqual | | Compares two TPoint values for equality | PtInRect | | Tests to see if a point lies within a rectangle | Rect | | Create a TRect value from 2 points or 4 coordinates | TPoint | | Holds X and Y integer values | TRect | | Holds rectangle coordinate values |
|
Download this web site as a Windows program.
|
|
|
|
Example code : Create rectangles using Rect and Bounds | var
rectangle1, rectangle2 : TRect;
begin
 // Set up the first rectangle using the Rect function
 // Note that we override the Types version of Rect.
rectangle1 := Classes.Rect(Point(10, 60), Point(50, 80));
 // Set up an identical 2nd rectangle using the Bounds function
rectangle2 := Bounds(10, 60, 40, 20);
 // Display the top left and bottom right coords of each rectangle
ShowMessageFmt('Rectangle 1 coords = %d,%d,%d,%d',
[rectangle1.Left,
rectangle1.Top,
rectangle1.Right,
rectangle1.Bottom]);
ShowMessageFmt('Rectangle 2 coords = %d,%d,%d,%d',
[rectangle2.Left,
rectangle2.Top,
rectangle2.Right,
rectangle2.Bottom]);
end;
| Show full unit code | Rectangle 1 coords = 10,60,50,80
Rectangle 2 coords = 10,60,50,80 |
|
|