RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TControl.ClientRect Property

Specifies the size (in pixels) of a control's client area.

Pascal
property ClientRect: TRect;
C++
__property TRect ClientRect;

Read ClientRect to find the size of the client area of a control. ClientRect returns a rectangle with its Top and Left fields set to zero, and its Bottom and Right fields set to the control's Height and Width, respectively. ClientRect is equivalent to Rect(0, 0, ClientWidth, ClientHeight). 

A point is considered within the control's client rectangle if it lies on the left or top side but not if it lies on the right or bottom side. That is, to be inside the client rectangle, the x-coordinate must be greater than or equal to ClientRect.Left and less than ClientRect.Right, and the y-coordinate must be greater than or equal to ClientRect.Top and less than ClientRect.Bottom.

Note: ClientRect is the size of the physical client area of the control, not its logical client area. If the control supports scrolling, the ClientRect is not the entire scrolling range, but only the region that is available at any given time.
 

C++ Examples: 

 

/*
The following code uses ClientRect to find and draw a line
from the top left to the bottom right of the current
control.  Select a TControl in the ListBox list.  This
example assumes that the current object is a descendent of
TControl and has a public Canvas property.
*/
{
  TPoint APoint = Point(X, Y);
  int Index = ListBox1->ItemAtPos(APoint, True);
  TToolBar *myToolBar;
  TClass ClassRef = ListBox1->Items->Objects[Index]->ClassType();
  if (String(ClassRef->ClassName()) == "TToolBar")
  {
    myToolBar = dynamic_cast<TToolBar *>(ListBox1->Items->Objects[Index]);
    // make sure we are using the TControls canvas and not the from's!
    myToolBar->Canvas->MoveTo(myToolBar->ClientRect.Left, myToolBar->ClientRect.Top);
    myToolBar->Canvas->LineTo(myToolBar->ClientRect.Right, myToolBar->ClientRect.Bottom);
    myToolBar = NULL;
  }
}

 

Delphi Examples: 

{
The following code uses ClientRect to find and draw a line
from the top left to the bottom right of the current
control.  Select a TControl in the ListBox list.  This
example assumes that the current object is a descendent of
TControl and has a public Canvas property.
}
  if (ListBox1.Items.Objects[Index] is TToolBar) then
  begin
    myToolBar:= (ListBox1.Items.Objects[Index] as TToolBar);
    with myToolBar.ClientRect do
    begin // make sure we are using the TControls canvas and not the from's!
      myToolBar.Canvas.MoveTo(Left, Top);
      myToolBar.Canvas.LineTo(Right, Bottom);
    end;
  myToolBar:= nil;
  end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!