BoundsRect (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This code resizes the active control to twice as wide and half as high.

Code

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;
}
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
  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);
}

Uses

See Also