RAD Studio VCL Reference
|
Indicates the page control object that contains the tab sheet.
property PageControl: TPageControl;
__property TPageControl PageControl;
Read PageControl to gain access to the page control object that uses the tab sheet. The properties and methods of the PageControl object can be used to locate the selected page, iterate through the other pages in the page control, or change the display properties of the tabs.
Set PageControl to remove the tab sheet from its current page control (if any) and insert it into a new page control.
C++ Examples:
/* 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 the user changes tabs. The message dialog contains the captions for the tabs immediately before and after the active tab. */ void __fastcall TForm1::FormCreate(TObject *Sender) { 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 = AnsiString("Page") + IntToStr(i); pPage->Name = AnsiString("ts") + pPage->Caption; } } void __fastcall TForm1::PageControl1Change(TObject *Sender) { AnsiString 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(AnsiString("Previous tab caption: '") + PrevCaption + AnsiString("' Next tab Caption: '") + NextCaption + AnsiString("'")); }
/* This example dynamically creates a Page Control, then a series of Tab Sheets on the Page Control. */ #include <Comctrls.hpp> TPageControl* ppc; const int MAXTABS = 3; TTabSheet* pts[MAXTABS]; const char * ppcTabTitles[] = { "ShortString", "Orders", "Items", "Parts" }; int iTabTitles = sizeof(ppcTabTitles)/sizeof(ppcTabTitles[0]); const TColor colorPalette[12] = { clRed, clGreen, clYellow, clBlue, clWhite, clFuchsia, clTeal, clNavy, clMaroon, clLime, clOlive, clPurple}; void __fastcall TForm1::FormCreate(TObject *Sender) { ppc = new TPageControl(this); // The owner (this) will clean this up. ppc->Parent = this; ppc->Align = alClient; for (int i=0;i<iTabTitles;i++) { pts[i] = new TTabSheet(this); // The owner (this) will clean this up. pts[i]->PageControl = ppc; pts[i]->Name = AnsiString("pts") + ppcTabTitles[i]; pts[i]->Caption = ppcTabTitles[i]; pts[i]->Brush->Color = colorPalette[i]; } }
Delphi Examples:
{ 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 the user changes tabs. The message dialog contains the captions for the tabs immediately before and after the active tab. } procedure TForm1.FormCreate(Sender: TObject); var i: Integer; begin for i := 0 to 9 do with TTabSheet.Create(Self) do begin PageControl := PageControl1; Caption := 'TabSheet #' + IntToStr(i); end; end; procedure TForm1.PageControl1Change(Sender: TObject); var PrevCaption, NextCaption: ShortString; begin with (Sender as TPageControl) do begin PrevCaption := FindNextPage(ActivePage, False, False).Caption; NextCaption := FindNextPage(ActivePage, True, False).Caption; end; ShowMessage('Previous tab caption: "' + PrevCaption + '" Next tab Caption: "' + NextCaption + '"'); end;
{ This example dynamically creates a Page Control, then a series of Tab Sheets on the Page Control. } var PageControl1: TPageControl; pts: array[0..3] of TTabSheet; const TabTitles: array[0..3] of ShortString = ('Customer', 'Orders', 'Items', 'Parts' ); procedure TForm1.FormCreate(Sender: TObject); const colorpalette: Array[0..11] of TColor = ( clRed, clGreen, clYellow, clBlue, clWhite, clFuchsia, clTeal, clNavy, clMaroon, clLime, clOlive, clPurple); var i: Integer; begin PageControl1 := TPageControl.Create(Self); PageControl1.Parent := Self; PageControl1.Align := alClient; for i := Low(TabTitles) to High(TabTitles) do begin pts[i]:= TTabSheet.Create(PageControl1); with pts[i] do begin PageControl := PageControl1; Name := 'ts' + TabTitles[i]; Caption := TabTitles[i]; Brush.Color := colorPalette[i]; end; end; end; procedure TForm1.FormDestroy(Sender: TObject); var i: Integer; begin for i := Low(TabTitles) to High(TabTitles) do begin pts[i].Free; end; PageControl1.Free; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|