请问怎样动态创建一个panel

解决方案 »

  1.   

    a:tpanel1;
    begin
      a:= tpanel1.create(nil);
     a......
    //or
      with tpanel1.create(nil) do
        begin
        try 
           ....
        finally
            freeandnil();
       end;
    end
      

  2.   

    1)还需要指定该panel的位置(Left,Top),大小(Width,Height),Parent,Name;
    2)建议将TPanel.Create()的参数设置为所在的Form
    3)之前声明的TPanel型变量只是个指针,应该对刚生成的Panel的Name赋值,以便于别的下次引用.
    4)记得必要时要主动释放.
      

  3.   

    Tpanel.Create(Self).Name := 'panel1';//命名
        with Tpanel(FindComponent('panel1')) do
        begin
          Left := 10;
          Top :=  20;
          Parent := self;
        end;
      

  4.   

    // 我都是用这这种方法来建立,动态控件的,当然也包括Form
    // 个人觉得这种方法是最好的
    Var
          Panel : TPanel ;
    Begin
          Panel := TPanel.Create(nil) ; // nil 也可为 Self  或 Form 
          Panel.Top := 100 ;
          Panel.Left := 100 ;
          Panel.Height := 100 ;
          Panel.Width := 100 ;
         .............
    End ;