TRectCenteredRect (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example illustrates how to use the CenteredRect method to return a centered rectangle from another rectangle.

Code

#include <tchar.h>
#include <stdio.h>
#include <system.types.hpp>

int _tmain(int argc, _TCHAR* argv[])
{
	TRect *aRectangle1 = new TRect(2,3,7,8);
	printf("%d %d %d %d\n",aRectangle1->Left,aRectangle1->Top,aRectangle1->Right,aRectangle1->Bottom);
        // The console will output: 2 3 7 8, representing the coordinates of the corners of aRectangle1

	TRect *aRectangle2 = new TRect(5,4,10,1);
	printf("%d %d %d %d\n",aRectangle2->Left,aRectangle2->Top,aRectangle2->Right,aRectangle2->Bottom);
        // The console will output: 5 4 10 1, representing the coordinates of the corners of aRectangle2

        *aRectangle2= aRectangle1->CenteredRect(* aRectangle2);
        printf("%d %d %d %d\n",aRectangle2->Left,aRectangle2->Top,aRectangle2->Right,aRectangle2->Bottom);
        // The console will output: 2 6 7 4, representing the coordinates of the corners of aRectangle2, centered into aRectangle1

	return 0;
}

Uses