如何创建动态BUTTON并且保存 用form里面固定button创建动态的button.在结束此程序时,下次打开时动态BUTTON还有在并不消失......要有哪种文件型保存动态BUTTON. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1.動態創建button:procedure TForm1.Button1Click(Sender: TObject); var button2:tbutton; begin button2:=tbutton.create(self); button2.Parent:=form1; button2.Caption:= 'heoo '; button2.Left:=100; button2.Top:=100; button2.Height:=100; button2.Width:=100; button2.show; end; 2.完整的:unit Unit1; interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 = class(TForm) btnAddButton: TButton; btnDeleteLast: TButton; procedure btnAddButtonClick(Sender: TObject); procedure btnDeleteLastClick(Sender: TObject);private { Private declarations } procedure CustomButtonClick(Sender: TObject);public { Public declarations }end;varForm1: TForm1;implementation{$R *.dfm}procedure TForm1.btnAddButtonClick(Sender: TObject);varNewButton: TButton; // 新 Button的指针begin// 在内存中创建一个 Button,拥有者为self,这样当窗体 destory时,这个新button// 能够被自动释放NewButton := TButton.Create(Self);With NewButton dobegin Top := 60; // button 的出现的坐标 Width := 60; // button 的宽度 Left := Width * (Self.ControlCount - 2); Parent := Self; // 指明在那个窗体显示 OnClick := CustomButtonClick; // 指定button click事件 Caption := 'Button' + IntToStr(Self.ControlCount - 2);end; // withend;procedure TForm1.btnDeleteLastClick(Sender: TObject);begin// 确定窗体上有新的buttonif Self.ControlCount > 2 then // 删除最后新建的 button TButton(Controls[ControlCount - 1]).Destroy;end;procedure TForm1.CustomButtonClick(Sender: TObject);begin// 根据 Sender 来判断哪个新建的button clickShowMessage(TButton(Sender).Caption + ' Pressed');end;end 3.下次打開程序動態創建的button還在?這裡提供個思路,只供LZ參考:a.在窗體create時,動態去執行創建button的事件;b.可編寫一動態創建button過程,在show時調用;c.可將上次動態創建的button所有屬性值寫入ini文件,下次打開時根據ini值再創建還原回來... Delphi有持久化机制,TStream、TWriter、TReader可以用ReadComponent、WriteComponent方法来读取和写入控件 怎么实现这样record类型的定义? 请教这样一个sql怎么写? 如何获取本机真实的外网IP地址 【裸体后空翻3周半加转体1080度双膝落地跪求】视频通讯相关问题,有经验的大虾进来!(在线) INDY IDTCPSERVER的一点疑问! 在用ADO时为何回出错? 请教各位大侠了 delphi Tchart中使用Tpointseries 画点状图,如何改变点的形状,如圆点,叉号,小三角... 请教:Listview中ListItem重名问题!!!! 动态创建一个TCombobox的问题 TMainMenu如果修改背景色 delphi封装dll
var
button2:tbutton;
begin
button2:=tbutton.create(self);
button2.Parent:=form1;
button2.Caption:= 'heoo ';
button2.Left:=100;
button2.Top:=100;
button2.Height:=100;
button2.Width:=100;
button2.show;
end;
interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;type
TForm1 = class(TForm)
btnAddButton: TButton;
btnDeleteLast: TButton;
procedure btnAddButtonClick(Sender: TObject);
procedure btnDeleteLastClick(Sender: TObject);
private
{ Private declarations }
procedure CustomButtonClick(Sender: TObject);
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.btnAddButtonClick(Sender: TObject);
var
NewButton: TButton; // 新 Button的指针
begin
// 在内存中创建一个 Button,拥有者为self,这样当窗体 destory时,这个新button
// 能够被自动释放
NewButton := TButton.Create(Self);With NewButton do
begin
Top := 60; // button 的出现的坐标
Width := 60; // button 的宽度
Left := Width * (Self.ControlCount - 2);
Parent := Self; // 指明在那个窗体显示
OnClick := CustomButtonClick; // 指定button click事件
Caption := 'Button' + IntToStr(Self.ControlCount - 2);
end; // with
end;procedure TForm1.btnDeleteLastClick(Sender: TObject);
begin
// 确定窗体上有新的button
if Self.ControlCount > 2 then
// 删除最后新建的 button
TButton(Controls[ControlCount - 1]).Destroy;
end;procedure TForm1.CustomButtonClick(Sender: TObject);
begin
// 根据 Sender 来判断哪个新建的button click
ShowMessage(TButton(Sender).Caption + ' Pressed');
end;end
a.在窗體create時,動態去執行創建button的事件;
b.可編寫一動態創建button過程,在show時調用;
c.可將上次動態創建的button所有屬性值寫入ini文件,下次打開時根據ini值再創建還原回來...