TRectContains (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example illustrates how to use the Contains method to test whether a point or a rectangle is located within the rectangle.

Code

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

int _tmain(int argc, _TCHAR* argv[])
{
	bool flag1,flag2;

	TRect *aRectangle = new TRect(2,3,7,8);
	printf("%d %d %d %d\n",aRectangle->Left,aRectangle->Top,aRectangle->Right,aRectangle->Bottom);
        // The console will output: 2 3 7 8, representing the coordinates of the corners of aRectangle
	
        TPoint *aPoint= new TPoint(10,10);
        printf("%d %d\n", aPoint->X,aPoint->Y);
        //The console will output: 10 10, representing the coordinates of the aPoint 
 
	flag1=aRectangle->Contains(*aPoint);
	if (flag1)
	{
		printf("aRectangle contains aPoint");
	}
	else
	{
		printf("aRectangle does not contain aPoint");
	}
        //The console will output: aRectangle does not contain aPoint
        printf("\n");         

	TRect *aRectangle1= new TRect(4,4,5,5);
        printf("%d %d %d %d\n",aRectangle1->Left,aRectangle1->Top,aRectangle1->Right,aRectangle1->Bottom);
        // The console will output: 4 4 5 5, representing the coordinates of the corners of aRectangle1
	
	flag2=aRectangle->Contains(*aRectangle1);
	if (flag2)
	{
		printf("aRectangle contains aRectangle1");
	}
	else
	{
		printf("aRectangle does not contain aRectangle1");
	}
        //The console will output: aRectangle contains aRectangle1

	return 0;
}

Uses