TabSheetPageControl (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example requires a new TPageControl, with no new pages created at design time. The form OnCreate event handler adds several new TabSheet controls to the Page Control. The Page Control’s OnChange event handler displays a message dialog when you change tabs. The message dialog contains the captions for the tabs immediately before and after the active tab.

Code

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  for (int i = 0; i < 10; i++)
  {
	TTabSheet *pPage = new TTabSheet(PageControl1); // These tabsheets will be cleaned up by their owner (PageControl1).
    pPage->PageControl = PageControl1;
	pPage->Caption = String(L"મઽૠ૪Page") + IntToStr(i);
	pPage->Name = String(L"ts") + pPage->Caption;
  }
}

void __fastcall TForm1::PageControl1Change(TObject *Sender)
{
  String PrevCaption, NextCaption;
  TPageControl *pPC = dynamic_cast<TPageControl *>(Sender);
  PrevCaption = pPC->FindNextPage(pPC->ActivePage, false, false)->Caption;
  NextCaption = pPC->FindNextPage(pPC->ActivePage, true, false)->Caption;
  ShowMessage(String(L"Previous મઽૠ૪ tab caption: '") + PrevCaption +
	String(L"'  Next મઽૠ૪ tab Caption: '") + NextCaption + String(L"'"));
}

Uses