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

#include <vcl.h>
#pragma hdrstop

#include "TControlCanvas.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  int I;
  for (I = ComponentCount - 1; I >= 0; I--)
  {
	ListBox1->Items->InsertObject(
	  0, Form1->Components[I]->Name,
	  Form1->Components[I]);
  }
  ListBox1->Items->InsertObject(
	0, Form1->Name, Form1);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ListBox1MouseDown(TObject *Sender, TMouseButton Button,
      TShiftState Shift, int X, int Y)
{
// BeginExample: TToolBarCanvas
// Property: ComCtrls.TToolBar.Canvas
// Property: Controls.TControl.ClientRect

// BeginCode
/*
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;
  }
}
// EndCode
// EndExample: TToolBarCanvas
// BeginExample: TStatusBarCanvas
// Property: ComCtrls.TCustomStatusBar.Canvas

// BeginCode
/*
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);
  TStatusBar *myStatusBar;
  TClass ClassRef = ListBox1->Items->Objects[Index]->ClassType();
  if (String(ClassRef->ClassName()) == "TStatusBar")
  {
	myStatusBar = dynamic_cast<TStatusBar *>(ListBox1->Items->Objects[Index]);
	// make sure we are using the TControls canvas and not the from's!
	myStatusBar->Canvas->MoveTo(myStatusBar->ClientRect.Left, myStatusBar->ClientRect.Top);
	myStatusBar->Canvas->LineTo(myStatusBar->ClientRect.Right, myStatusBar->ClientRect.Bottom);
	myStatusBar = NULL;
  }
}
// EndCode
// EndExample: TStatusBarCanvas
{
  TPoint APoint = Point(X, Y);
  int Index = ListBox1->ItemAtPos(APoint, True);
  TDBText *myDBText;
  TClass ClassRef = ListBox1->Items->Objects[Index]->ClassType();
  if (String(ClassRef->ClassName()) == "TDBText")
  {
	myDBText = dynamic_cast<TDBText *>(ListBox1->Items->Objects[Index]);
	// make sure we are using the TControls canvas and not the from's!
	myDBText->Canvas->MoveTo(myDBText->ClientRect.Left, myDBText->ClientRect.Top);
	myDBText->Canvas->LineTo(myDBText->ClientRect.Right, myDBText->ClientRect.Bottom);
	myDBText = NULL;
  }
}
// BeginExample: TLabelCanvas
// Property: Controls.TGraphicControl.Canvas

// BeginCode
/*
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);
  TLabel *myLabel;
  TClass ClassRef = ListBox1->Items->Objects[Index]->ClassType();
  if (String(ClassRef->ClassName()) == "TLabel")
  {
	myLabel = dynamic_cast<TLabel *>(ListBox1->Items->Objects[Index]);
	// make sure we are using the TControls canvas and not the from's!
	myLabel->Canvas->MoveTo(myLabel->ClientRect.Left, myLabel->ClientRect.Top);
	myLabel->Canvas->LineTo(myLabel->ClientRect.Right, myLabel->ClientRect.Bottom);
	myLabel = NULL;
  }
}
// EndCode
// EndExample: TLabelCanvas
// BeginExample: TImageCanvas
// Property: ExtCtrls.TImage.Canvas

// BeginCode
/*
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);
  TImage *myImage;
  TClass ClassRef = ListBox1->Items->Objects[Index]->ClassType();
  if (String(ClassRef->ClassName()) == "TImage")
  {
	myImage = dynamic_cast<TImage *>(ListBox1->Items->Objects[Index]);
	// make sure we are using the TControls canvas and not the from's!
	myImage->Canvas->MoveTo(myImage->ClientRect.Left, myImage->ClientRect.Top);
	myImage->Canvas->LineTo(myImage->ClientRect.Right, myImage->ClientRect.Bottom);
	myImage = NULL;
  }
}
// EndCode
// EndExample: TImageCanvas
{
  TPoint APoint = Point(X, Y);
  int Index = ListBox1->ItemAtPos(APoint, True);
  TPaintBox *myPaintBox;
  TClass ClassRef = ListBox1->Items->Objects[Index]->ClassType();
  if (String(ClassRef->ClassName()) == "TPaintBox")
  {
	myPaintBox = dynamic_cast<TPaintBox *>(ListBox1->Items->Objects[Index]);
	// make sure we are using the TControls canvas and not the from's!
	myPaintBox->Canvas->MoveTo(myPaintBox->ClientRect.Left, myPaintBox->ClientRect.Top);
	myPaintBox->Canvas->LineTo(myPaintBox->ClientRect.Right, myPaintBox->ClientRect.Bottom);
	myPaintBox = NULL;
  }
}
{
  TPoint APoint = Point(X, Y);
  int Index = ListBox1->ItemAtPos(APoint, True);
  TSplitter *mySplitter;
  TClass ClassRef = ListBox1->Items->Objects[Index]->ClassType();
  if (String(ClassRef->ClassName()) == "TSplitter")
  {
	mySplitter = dynamic_cast<TSplitter *>(ListBox1->Items->Objects[Index]);
	// make sure we are using the TControls canvas and not the from's!
	mySplitter->Canvas->MoveTo(mySplitter->ClientRect.Left, mySplitter->ClientRect.Top);
	mySplitter->Canvas->LineTo(mySplitter->ClientRect.Right, mySplitter->ClientRect.Bottom);
	mySplitter = NULL;
  }
}
// BeginExample: TListBoxCanvas
// Property: StdCtrls.TCustomListBox.Canvas

// BeginCode
/*
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);
  TListBox *myListBox;
  TClass ClassRef = ListBox1->Items->Objects[Index]->ClassType();
  if (String(ClassRef->ClassName()) == "TListBox")
  {
	myListBox = dynamic_cast<TListBox *>(ListBox1->Items->Objects[Index]);
	// make sure we are using the TControls canvas and not the from's!
	myListBox->Canvas->MoveTo(myListBox->ClientRect.Left, myListBox->ClientRect.Top);
	myListBox->Canvas->LineTo(myListBox->ClientRect.Right, myListBox->ClientRect.Bottom);
	myListBox = NULL;
  }
}
// EndCode
// EndExample: TListBoxCanvas
// BeginExample: TStringGridCanvas
// Property: Controls.TCustomControl.Canvas

// BeginCode
/*
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);
  TStringGrid *myStringGrid;
  TClass ClassRef = ListBox1->Items->Objects[Index]->ClassType();
  if (String(ClassRef->ClassName()) == "TStringGrid")
  {
	myStringGrid = dynamic_cast<TStringGrid *>(ListBox1->Items->Objects[Index]);
	// make sure we are using the TControls canvas and not the from's!
	myStringGrid->Canvas->MoveTo(myStringGrid->ClientRect.Left, myStringGrid->ClientRect.Top);
	myStringGrid->Canvas->LineTo(myStringGrid->ClientRect.Right, myStringGrid->ClientRect.Bottom);
	myStringGrid = NULL;
  }
}
// EndCode
// EndExample: TStringGridCanvas
{
  TPoint APoint = Point(X, Y);
  int Index = ListBox1->ItemAtPos(APoint, True);
  TControlBar *myControlBar;
  TClass ClassRef = ListBox1->Items->Objects[Index]->ClassType();
  if (String(ClassRef->ClassName()) == "TControlBar")
  {
	myControlBar = dynamic_cast<TControlBar *>(ListBox1->Items->Objects[Index]);
	// make sure we are using the TControls canvas and not the from's!
	myControlBar->Canvas->MoveTo(myControlBar->ClientRect.Left, myControlBar->ClientRect.Top);
	myControlBar->Canvas->LineTo(myControlBar->ClientRect.Right, myControlBar->ClientRect.Bottom);
	myControlBar = NULL;
  }
}
// BeginExample: TComboBoxCanvas
// Property: StdCtrls.TCustomCombo.Canvas

// BeginCode
/*
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);
  TComboBox *myComboBox;
  TClass ClassRef = ListBox1->Items->Objects[Index]->ClassType();
  if (String(ClassRef->ClassName()) == "TComboBox")
  {
	myComboBox = dynamic_cast<TComboBox *>(ListBox1->Items->Objects[Index]);
	// make sure we are using the TControls canvas and not the from's!
	myComboBox->Canvas->MoveTo(myComboBox->ClientRect.Left, myComboBox->ClientRect.Top);
	myComboBox->Canvas->LineTo(myComboBox->ClientRect.Right, myComboBox->ClientRect.Bottom);
	myComboBox = NULL;
  }
}
// EndCode
// EndExample: TComboBoxCanvas
// BeginExample: TTreeViewCanvas
// Property: ComCtrls.TCustomTreeView.Canvas

// BeginCode
/*
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);
  TTreeView *myTreeView;
  TClass ClassRef = ListBox1->Items->Objects[Index]->ClassType();
  if (String(ClassRef->ClassName()) == "TTreeView")
  {
	myTreeView = dynamic_cast<TTreeView *>(ListBox1->Items->Objects[Index]);
	// make sure we are using the TControls canvas and not the from's!
	myTreeView->Canvas->MoveTo(myTreeView->ClientRect.Left, myTreeView->ClientRect.Top);
	myTreeView->Canvas->LineTo(myTreeView->ClientRect.Right, myTreeView->ClientRect.Bottom);
	myTreeView = NULL;
  }
}
// EndCode
// EndExample: TTreeViewCanvas
// BeginExample: TListViewCanvas
// Property: ComCtrls.TCustomListView.Canvas

// BeginCode
/*
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);
  TListView *myListView;
  TClass ClassRef = ListBox1->Items->Objects[Index]->ClassType();
  if (String(ClassRef->ClassName()) == "TListView")
  {
	myListView = dynamic_cast<TListView *>(ListBox1->Items->Objects[Index]);
	// make sure we are using the TControls canvas and not the from's!
	myListView->Canvas->MoveTo(myListView->ClientRect.Left, myListView->ClientRect.Top);
	myListView->Canvas->LineTo(myListView->ClientRect.Right, myListView->ClientRect.Bottom);
	myListView = NULL;
  }
}
// EndCode
// EndExample: TListViewCanvas
// BeginExample: TFormCanvas
// Property: Forms.TCustomForm.Canvas

// BeginCode
/*
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);
  TForm1 *myForm;
  TClass ClassRef = ListBox1->Items->Objects[Index]->ClassType();
  if (String(ClassRef->ClassName()) == "TForm1")
  {
	myForm = dynamic_cast<TForm1 *>(ListBox1->Items->Objects[Index]);
	// make sure we are using the TControls canvas and not the from's!
	myForm->Canvas->MoveTo(myForm->ClientRect.Left, myForm->ClientRect.Top);
	myForm->Canvas->LineTo(myForm->ClientRect.Right, myForm->ClientRect.Bottom);
	myForm = NULL;
  }
}
// EndCode
// EndExample: TFormCanvas
// BeginExample: TPageControlCanvas
// Property: ComCtrls.TCustomTabControl.Canvas

// BeginCode
/*
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);
  TPageControl *myPageControl;
  TClass ClassRef = ListBox1->Items->Objects[Index]->ClassType();
  if (String(ClassRef->ClassName()) == "TPageControl")
  {
	myPageControl = dynamic_cast<TPageControl *>(ListBox1->Items->Objects[Index]);
	// make sure we are using the TControls canvas and not the from's!
	myPageControl->Canvas->MoveTo(myPageControl->ClientRect.Left, myPageControl->ClientRect.Top);
	myPageControl->Canvas->LineTo(myPageControl->ClientRect.Right, myPageControl->ClientRect.Bottom);
	myPageControl = NULL;
  }
}
// EndCode
// EndExample: TPageControlCanvas
}
//---------------------------------------------------------------------------

void __fastcall TForm1::PaintBox1Paint(TObject *Sender)
{
  PaintBox1->Canvas->Draw(0,0, Image1->Picture->Graphic);
}
//---------------------------------------------------------------------------

