嘿嘿 偶来~
procedure TForm1.urlbuttonclick(Sender:Tobject);
begin
//按钮按下的事件
end;
procedure TForm1.Button1Click(Sender: TObject);
var
h,i:integer;
f:Tinifile;
strlist:Tstringlist;
btn:Tbutton;
fname:string;
begin
fname:='c:/11.ini'; //ini文件位置
strlist:=Tstringlist.Create;
if fileexists(fname) then
try
f:=Tinifile.Create(fname);
f.ReadSection('INI',strlist);
h:=listbox1.Top+1;
for i:=0 to strlist.Count-1 do
begin
btn:=Tbutton.Create(nil);
btn.Left:=listbox1.Left+1;
btn.Width:=listbox1.Width-2;
btn.Top:=h;
btn.Height:=listbox1.Font.Size*2;//这里是设置按钮高度,listbox行高根据字体变化而改变
//我没找到字体大小与行高之间的变化规律,你自己多试试
h:=h+listbox1.Font.Size*4; //空一行,行高同上
btn.OnClick:=urlbuttonclick;
btn.Hint:=f.ReadString('INI',strlist.Strings,'');
btn.Caption:=strlist.Strings;
btn.Parent:=self;
end;
finally
strlist.Free;
f.Free;
end;
end;