如何在form上动态添加一个按钮?用for循环,for i:=0 to 10 then写代码添加按钮10个按钮,请提供源码.

解决方案 »

  1.   

    var 
      mybutton:tbutton;
      i:integer;
    begin
      for i:=1 to 10 do
      begin
        mybutton;=tbutton.create(self);
        mybutton.caption:="button"+i;
        mybutton.left:=i*10+20;
        mybutton.top:=i*10+20;
      end;
      

  2.   

    var
      btn: array[1..10] of TButton;
      i: Integer;
    begin
      for i := 1 to 10 do
      begin
        btn[i] := TButton.Create(self);
        btn[i].Caption := 'Button' + IntToStr(i);
        btn[i].Left := 80;
        btn[i].Top := 20 + i*25;
        btn[i].Parent := self;
      end;
    end;
      

  3.   

    var 
      mybutton:tbutton;
      i:integer;
    begin
      for i:=1 to 10 do
      begin
        mybutton;=tbutton.create(self);
        mybutton.caption:="button"+inttoStr(i);
        mybutton.parent := self;
        mybutton.left:=i*10+20;
        mybutton.top:=i*10+20;
      end;
    end;
      

  4.   

    var 
      mybutton:tbutton;
      i:integer;
    begin
      for i:=1 to 10 do
      begin
        mybutton;=tbutton.create(self);
        mybutton.caption:="button"+inttoStr(i);
        mybutton.parent := self;
        mybutton.left:=i*10+20;
        mybutton.top:=i*10+20;
      end;
    end;
      

  5.   

    var
      btn: array[1..10] of TButton;
      i: Integer;
    begin
      for i := 1 to 10 do
      begin
        btn[i] := TButton.Create(self);
        btn[i].Caption := 'Button' + IntToStr(i);
        btn[i].Left := 80;
        btn[i].Top := 20 + i*25;
        btn[i].Parent := self;
      end;
    end;
      

  6.   

    var 
      mybutton:tbutton;
      i:integer;
    begin
      for i:=1 to 10 do
      begin
        mybutton;=tbutton.create(self);
        mybutton.caption:="button"+inttoStr(i);
        mybutton.parent := self;
        mybutton.left:=i*10+20;
        mybutton.top:=i*10+20;
      end;
    end;
      

  7.   

    那如果我在scrollbox上添加了按钮,如何全部删除?
      

  8.   

    先写一个事件,然后Mybutton.Onclick := 你自己写的事件。