RAD Studio VCL Reference
|
Specifies the bounding rectangle of the control, expressed in the coordinate system of the parent control.
property BoundsRect: TRect;
__property TRect BoundsRect;
Use BoundsRect as a quick way to obtain the pixel locations of all corners of the control all at once.
For example, the statement
R := Control.BoundsRect;
R = Control->BoundsRect;
corresponds to
R.Left := Control.Left; R.Top := Control.Top; R.Right := Control.Left + Control.Width; R.Bottom := Control.Top + Control.Height;
The origin of the pixel coordinate system is in the top left corner of the parent window.
C++ Examples:
/* This code resizes the active control to twice as wide and half as high: */ void __fastcall TForm1::ButtonTSClick(TObject *Sender) { TRect MyRect; if (myActiveControl == NULL) exit; MyRect = myActiveControl->BoundsRect; MyRect.Right = MyRect.Left + (MyRect.Right - MyRect.Left) / 2; MyRect.Bottom = MyRect.Top + 2 * (MyRect.Bottom - MyRect.Top); myActiveControl->BoundsRect = MyRect; } void __fastcall TForm1::ButtonSFClick(TObject *Sender) { TRect MyRect; if (myActiveControl == NULL) exit; MyRect = myActiveControl->BoundsRect; MyRect.Right = MyRect.Left + 2 * (MyRect.Right - MyRect.Left); MyRect.Bottom = MyRect.Top + (MyRect.Bottom - MyRect.Top) / 2; myActiveControl->BoundsRect = MyRect; } void __fastcall TForm1::FormCreate(TObject *Sender) { TComponent *Temp; TListItem *ListItem; ListView1->ViewStyle = vsList; ListItem = ListView1->Items->Add(); ListItem->Caption = "Components: "; for (int I = ComponentCount - 1; I >= 0; I--) { Temp = Components[I]; ListItem = ListView1->Items->Add(); ListItem->Caption = Temp->Name; } } void __fastcall TForm1::ListView1SelectItem(TObject *Sender, TListItem *Item, bool Selected) { TComponent *comp = FindComponent(Item->Caption); if (dynamic_cast<TWinControl *>(comp) != NULL) myActiveControl = dynamic_cast<TWinControl *>(comp); }
Delphi Examples:
{ This code resizes the active control to twice as wide and half as high: } procedure TForm1.ButtonSFClick(Sender: TObject); var MyRect: TRect; begin if (myActiveControl = nil) then exit; MyRect := myActiveControl.BoundsRect; MyRect.Right := MyRect.Left + (MyRect.Right - MyRect.Left) * 2; MyRect.Bottom := MyRect.Top + (MyRect.Bottom - MyRect.Top) div 2; myActiveControl.BoundsRect := MyRect; end; procedure TForm1.ButtonTSClick(Sender: TObject); var MyRect: TRect; begin if (myActiveControl = nil) then exit; MyRect := myActiveControl.BoundsRect; MyRect.Right := MyRect.Left + (MyRect.Right - MyRect.Left) div 2; MyRect.Bottom := MyRect.Top + (MyRect.Bottom - MyRect.Top) * 2; myActiveControl.BoundsRect := MyRect; end; procedure TForm1.FormCreate(Sender: TObject); var I: Integer; Temp: TComponent; ListItem: TListItem; begin ListView1.ViewStyle := vsList; ListItem := ListView1.Items.Add; ListItem.Caption := 'Components: '; for I := ComponentCount - 1 downto 0 do begin Temp := Components[I]; begin ListItem := ListView1.Items.Add; ListItem.Caption := Temp.Name; end; end; end; procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean); var comp: TComponent; begin comp := FindComponent(Item.Caption); if comp is TWinControl then myActiveControl := TWinControl(comp); end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|