如何自动生成Button控件?

liao71 2010-09-18 11:08:48
如题,当然点击一按钮(Button)时如何自动生成指点数目的Button,谢谢,
...全文
144 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wxieyang 2010-09-19
  • 打赏
  • 举报
回复
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
begin
for i := 0 to 30 do
with TButton.Create(Self) do
begin
Parent := Self;
// + 3 是为了间隔开
// + 10 是为了不顶头开始排列
Top := (i div 7) * (Height + 3) + 10;
Left := (i mod 7) * (Width + 3) + 10;
end;
end;
dinoalex 2010-09-19
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 liao71 的回复:]
for i:= 0 to 10 do
begin
abutton:= tbutton.create(self);
abutton.parent:= self;
abutton.setbound(i+i*60,10,50,25); // 怎样排,似乎你怎么处理这里面的前两个参数
end;

这个怎么让他换行啊?比如7个排成一行,不行就换到下一行这样。
[/Quote]


const
colcount = 7
var
i,c: integer;
begin
c:= 0;
for i:= 0 to 20 do
begin
abutton:= tbutton.create(self);
abutton.parent:= self;
if (i mod colcount) = 0 then inc(c);
abutton.setbound(i+i*60,10+25*c,50,25);
end;
dinoalex 2010-09-18
  • 打赏
  • 举报
回复
视 乎
dinoalex 2010-09-18
  • 打赏
  • 举报
回复
for i:= 0 to 10 do
begin
abutton:= tbutton.create(self);
abutton.parent:= self;
abutton.setbound(i+i*60,10,50,25); // 怎样排,似乎你怎么处理这里面的前两个参数
end;
liao71 2010-09-18
  • 打赏
  • 举报
回复
就是生成多少个这样的按钮,排列起来,几行几列这样。
ecjtu5208 2010-09-18
  • 打赏
  • 举报
回复
什么叫指点数目?
自动生成代码如下:



procedure TForm1.Button1Click(Sender: TObject);
var
x:tbutton;
begin
x:=tbutton.Create(self);
x.parent:=form1;
end;
liao71 2010-09-18
  • 打赏
  • 举报
回复
for i:= 0 to 10 do
begin
abutton:= tbutton.create(self);
abutton.parent:= self;
abutton.setbound(i+i*60,10,50,25); // 怎样排,似乎你怎么处理这里面的前两个参数
end;

这个怎么让他换行啊?比如7个排成一行,不行就换到下一行这样。
YLCN2010 2010-09-18
  • 打赏
  • 举报
回复

Var
AButton: TButton;
I, J: Integer;
begin
for I:= 0 to 4 do
begin
for J := 0 to 3 do
begin
Abutton:= Tbutton.Create(Self);
Abutton.parent:= Self;
Abutton.Left := OneButton.Left + J * 6;
AButton.Top := OneButton.Top + OneButton.Width + I * 6;
AButton.Width := OneButton.Width;
AButton.Heigth := OneButton.Heigth;
end;
end;
end;

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧