如何动态创建按钮?以及如何让其响应click事件!
解决方案 »
- delphi dbgridth combobox字段 picklist列表无法显示
- 求WebBrowser显示网页如何放入线程
- listview怎样删除选中的多行?
- 请问用delphi7如何实文本分割?http://img.pconline.com.cn/images/bbs4/2005/09/06/1125983433862799.jpg
- 各位大哥,為什麼插入的日期會出錯?
- 数据应该如何入库??
- 请问dataobject单元在哪里?
- 如何将Delphi里用ADOQuery查询结果记录集封装到一个xml文件
- SQL 高手请进
- 一个简单的问题!!!
- 请高手指教我的程序错哪里(关于防止程序二次运行得)
- @@@@@@@@@@@@@@去看看印尼人怎么对付华人同胞的,太恐怖了@@@@@@@@@@@@@@@@@@@@@@@@@@@
sbutton.onclick:= ....
这种问题很多拉
搜索一下先吧
begin
showmessage('This Button caption is ' + TButton(Sender).Caption);
end;procedure TForm1.Button1Click(Sender: TObject);
var
AButton: TButton;
i: Integer;
begin
for i := 1 to 5 do
begin
AButton := TButton.Create(self);
AButton.Parent := self;
AButton.Top := i*100;
AButton.Caption := IntToStr(i*100);
AButton.OnClick := ButtonClick;
end;end;
var
b:TButton;
begin
B:=TButton.Create(self);
B.Parent:=self;
B.left:=100;
B.Top:=100;
B.Caption:='Button2';
// B.OnClick:=……
end;
谢谢你,你的代码有一处不明
abutton.parent=self;
这个self指谁?form 还是什么?????
BUTTON.Parent:=Panel1;
self指當前Form1
例如:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure aaa(sender:tobject);//过程
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
btn:tbutton;implementation{$R *.DFM}
procedure tform1.aaa(sender:tobject);
begin
showmessage('aaaaaaaaaa');
end;procedure TForm1.FormCreate(Sender: TObject);
begin
btn:=tbutton.Create(self);
btn.Parent:=form1;
btn.Visible:=true;
btn.onClick:=aaa;//赋过程名
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
btn.Free;
end;
end.