ActivePage (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example requires that a TPageControl already is on the form. Also, you must add pages to the TPageControl by right-clicking and selecting New Page. The example code will allow you to select the ActivePage property through the selection of a ComboBox item. During the form creation, the Combo Box control is loaded with the names of each of the tabs, as well as the instance pointers to the corresponding tab. When you select the Combo Box item, the associated TTabSheet object contained in the Combo Box Objects array is used to set the ActivePage property. Select the Lines property of the TRichEdit to enter a string. Select the string before justifying.

Code

void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
  TComboBox *pCB = dynamic_cast<TComboBox *>(Sender);
  if (pCB)
	PageControl1->ActivePage = dynamic_cast<TTabSheet *>(pCB->Items->Objects[pCB->ItemIndex]);
}

__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
  const TColor colorPalette[12] = {
	clRed, clGreen, clYellow, clBlue, clWhite, clFuchsia,
	clTeal, clNavy, clMaroon, clLime, clOlive, clPurple};
  for (int i = 0; i < PageControl1->PageCount; i++)
  {
	PageControl1->Pages[i]->Brush->Color = colorPalette[i];
	ComboBox1->Items->AddObject(PageControl1->Pages[i]->Name, PageControl1->Pages[i]);
  }
  ComboBox1->ItemIndex = 0;
  PageControl1->ActivePage = dynamic_cast<TTabSheet *>(ComboBox1->Items->Objects[ComboBox1->ItemIndex]);
}

Uses

See Also

Personal tools
Assistance