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

#include <vcl.h>
#pragma hdrstop

#include "PageControlChanging.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
// BeginExample: PageControlChanging
// Event: ComCtrls.TCustomTabControl.OnChanging

// BeginCode
/*
This project requires a TPageControl, several TTabSheets (to
add sheets, right click the Page Control and select "New
Page" from the context menu), and a TEdit control on the
first tab sheet.  The user is not allowed to change to a new
page if the active page is "TabSheet1" and there is no text
in the Edit Control.
*/
void __fastcall TForm1::PageControl1Changing(TObject *Sender, bool &AllowChange)
{
  if ((dynamic_cast<TPageControl *>(Sender))->ActivePage == TabSheet1)
	AllowChange = (!Edit1->Text.IsEmpty());
  else
    AllowChange = true;
  if (AllowChange == false)
  {
	MessageBeep(0);
	Edit1->SetFocus();
  }
}
// EndCode
// EndExample: PageControlChanging

void __fastcall TForm1::FormCreate(TObject *Sender)
{
int i;
const TColor colorPalette[12] = {
	clRed, clGreen, clYellow, clBlue, clWhite, clFuchsia,
	clTeal, clNavy, clMaroon, clLime, clOlive, clPurple};
for (i = 0; i < PageControl1->PageCount; i++)
	PageControl1->Pages[i]->Brush->Color = colorPalette[i];
}
//---------------------------------------------------------------------------

