请问怎样用程序在Notebook任意Page上面添加不同的组件,如Button等,谢谢。

解决方案 »

  1.   

    下面的代码可以实现在notebook上动态添加button
    你可以在这个基础上修改成你想要的状态;{
     测试环境:delphi6/win2000
    }
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Edit1: TEdit;
        Notebook1: TNotebook;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    var
      Form1: TForm1;
       Nid :Longint;
    implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var
       btn : Tbutton;
    begin
       btn:=Tbutton.Create(nil);
       btn.Top := 20;
       btn.Left := 40;
       btn.Caption := 'NPbutton';
       btn.Name := 'btn';
       btn.Parent := TWincontrol(Nid);
       btn.Show;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      if notebook1.PageIndex<2 then
      notebook1.PageIndex := Notebook1.PageIndex +1
      else
      Notebook1.PageIndex :=0;
      edit1.Text := inttostr(Notebook1.pageindex);
      Nid:=Longint(Notebook1.Controls[Notebook1.pageindex]);
    end;end.