0

Best way to 'insert' a page in a TPageControl if i already have many pages full of controls? Let's say i want to insert a new page before TabSheet1.

Thanks.

UPDATE : At design time.

4

2 回答 2

13

Rightclick on the pagecontrol, and click New Page

After that, set the PageIndex property to place the new page where you want to have it.

于 2009-10-12T06:50:45.210 回答
9

You can try this

procedure TForm13.Button1Click(Sender: TObject);
Var
   tabSheet: TTabSheet;
   AComponent: TComponent;
   aIndex: Integer;
begin
   aIndex:=-1;

   AComponent := FindComponent('TabSheet1');
   if Assigned(AComponent) then
     if AComponent is TTabSheet then
       aIndex := TTabSheet(AComponent).PageIndex; //get the index of the 'TabSheet1'  

   tabSheet := TTabSheet.Create(PageControl1);
   tabSheet.PageControl := PageControl1;
   tabSheet.Caption := 'My TabSheet'+IntToStr(PageControl1.PageCount);
   if aIndex>-1 then
     tabSheet.PageIndex := aIndex; //Set the index of the new TabSheet
end;

Update

In Designtime you must set the PageIndex Property to the PageIndex of the TabSheet1.

Bye.

于 2009-10-12T06:22:13.037 回答