var MyB: array[0..10] of TSpeedButton; begin MyB[0]:=TSpeedButton.Create(Self); MyB[0].Parent:=Form1; MyB[0].Left:=20; MyB[0].Top:=10; //MyB.OnClick:=MyOnClick;//MyOnClick 响应事件的过程 MyB[0].Show; ....可用WHITE end;
同意: hch_45(んこん) !
先在form上面放一个speedbutton控件, 并且speedbuton.visible:=false;然后加入下面代码: public { Public declarations } end;var Form1: TForm1; aa:array [0..20] of TSpeedButton; i:integer; implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);begin for i:=0 to 20 do begin aa[i]:=tspeedbutton.create(self); aa[i].parent:=self; aa[i].left:=i; aa[i].top:=i; aa[i].show; end; end; end.
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Buttons, StdCtrls;type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; Button: array of TSpeedButton; implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); var i: integer; procedure CreateSpeedButton(index: integer; Form: TForm); begin button[index]:=TSpeedButton.Create(form); button[index].Caption:= 'SpeedButton'+IntToStr(index); button[index].Name:= 'SpeedButton'+IntToStr(index); button[index].Left:= 20 * index; button[index].Width:= 30; button[index].Top:= 20; // button[index].OnClick:= buttonClickEvent; button[index].Parent:= form; end; begin setlength(button, 10); for i:= 0 to high(button) - 1 do CreateSpeedButton(i, form1); end;procedure TForm1.FormDestroy(Sender: TObject); var i: integer; begin for i:= high(button) - 1 downto 0 do button[i].Free; setlength(button, 0); end;end.
在uses中加入Button然后加入下面代码,,public { Public declarations } end;var Form1: TForm1; aa:array [0..20] of TSpeedButton; i:integer; implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);begin for i:=0 to 20 do begin aa[i]:=tspeedbutton.create(self); aa[i].parent:=self; aa[i].left:=i; aa[i].top:=i; aa[i].show; end; end; end.
MyB: array[0..10] of TSpeedButton;
begin
MyB[0]:=TSpeedButton.Create(Self);
MyB[0].Parent:=Form1;
MyB[0].Left:=20;
MyB[0].Top:=10;
//MyB.OnClick:=MyOnClick;//MyOnClick 响应事件的过程
MyB[0].Show;
....可用WHITE
end;
并且speedbuton.visible:=false;然后加入下面代码: public
{ Public declarations }
end;var
Form1: TForm1;
aa:array [0..20] of TSpeedButton;
i:integer;
implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);begin
for i:=0 to 20 do
begin
aa[i]:=tspeedbutton.create(self);
aa[i].parent:=self;
aa[i].left:=i;
aa[i].top:=i;
aa[i].show;
end;
end;
end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
Button: array of TSpeedButton;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
i: integer; procedure CreateSpeedButton(index: integer; Form: TForm);
begin
button[index]:=TSpeedButton.Create(form);
button[index].Caption:= 'SpeedButton'+IntToStr(index);
button[index].Name:= 'SpeedButton'+IntToStr(index);
button[index].Left:= 20 * index;
button[index].Width:= 30;
button[index].Top:= 20;
// button[index].OnClick:= buttonClickEvent;
button[index].Parent:= form;
end;
begin
setlength(button, 10);
for i:= 0 to high(button) - 1 do
CreateSpeedButton(i, form1);
end;procedure TForm1.FormDestroy(Sender: TObject);
var
i: integer;
begin
for i:= high(button) - 1 downto 0 do
button[i].Free;
setlength(button, 0);
end;end.
{ Public declarations }
end;var
Form1: TForm1;
aa:array [0..20] of TSpeedButton;
i:integer;
implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);begin
for i:=0 to 20 do
begin
aa[i]:=tspeedbutton.create(self);
aa[i].parent:=self;
aa[i].left:=i;
aa[i].top:=i;
aa[i].show;
end;
end;
end.