How Can I Add Pages to a TTabbedNotebook at Run-time?

This example shows you how to add a page to a TTabbedNotebook at run-time. It also shows how to add controls to it. Original code by Graham Mainwaring.

  procedure AddPage;
  var
    btnNew : TButton;
    NewPage: TTabPage;
    wNumber: Word;
  begin
    { Create the new TTabPage object }
    NewPage := TTabPage.Create(Application);
    { The page must be a child of the notebook }
    TabbedNotebook1.InsertControl(NewPage);
    { Add text to the notebook's Pages property. This will cause the new page to be added as the last tab on the notebook }
    wNumber := TabbedNotebook1.Pages.Add('New Page');
    TabbedNotebook1.PagesObjects[wNumber] := NewPage;
    { The page needs controls on it; here's how to add one }
    btnNew := TButton.Create(Self);
    TWinControl(TabbedNotebook1.Pages.Objects[wNumber]).InsertControl(btnNew);
    with btnNew do begin
      Top := 10;
      Height := 30;
      Width := 100;
      Caption := 'OK';
    end;
  end;

Tags: , , , , ,

No Comments Yet

You can be the first to comment!

Leave a comment

OpenID Login

Standard Login