代码之家  ›  专栏  ›  技术社区  ›  volvox

如何在tpagecontrol中“插入”新页

  •  0
  • volvox  · 技术社区  · 15 年前

    在tpagecontrol中“插入”页面的最佳方法(如果我已经有许多页面充满了控件)?假设我想在Tabsheet1前面插入一个新页面。

    谢谢。

    更新:在设计时。

    2 回复  |  直到 12 年前
        1
  •  9
  •   mg30rg    12 年前

    你可以试试这个

    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;
    

    更新

    在DesignTime中,必须将PageIndex属性设置为TabSheet1的PageIndex。

    再见。

        2
  •  13
  •   Wouter van Nifterick Andrey    15 年前

    右键单击 在页面控件上,单击 新页

    之后,设置 PageIndex 属性将新页放置到您希望的位置。