//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "BoundsRect.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TWinControl *myActiveControl;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
// BeginExample: BoundsRect
// Property: Controls.TControl.BoundsRect
// Event: ComCtrls.TCustomListView.OnSelectItem
// Method: Classes.TComponent.FindComponent

// BeginCode
/*
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);
}
// EndCode
// EndExample: BoundsRect
//---------------------------------------------------------------------------
