Delphi:如何使TButtons 3x3? [英] Delphi: How to make TButtons 3x3?

查看:126
本文介绍了Delphi:如何使TButtons 3x3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了多个TButton.

I've created multi TButtons.

问题是我希望创建的按钮看起来像3x3.

Problem is I'd like created buttons looks like 3x3.

该怎么做? 注意:按钮会更多!

How to do that? Note: Buttons will be more!

我的代码:

procedure TForm1.CreateButtonsClick(Sender: TObject);
var
i:integer;
B: TButton;
begin
for i:= 1 to 7 do
  begin
    B := TButton.Create(Self);
    B.Text := Format('Button %d', [i]);
    B.Parent := Self;
    B.Height := 23;
    B.Width := 100;
    B.Position.X:=25 + i* 105;
    B.Position.Y:=70;
  end;
end;

推荐答案

自从您提到使用TGridLayout以来,这里有一些代码展示了如何修改您的代码以将某些TButton布局为一个,类似于屏幕截图:

Since you mentioned using a TGridLayout, here is some code which show how to modify your code to lay out some TButtons in one, in a manner resembling your screenshot:

procedure TForm1.AButtonClick(Sender: TObject);
begin
  ShowMessage(TButton(Sender).Text);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  CreateButtons;
end;

procedure TForm1.CreateButtons;
var
  i:integer;
  B: TButton;
begin
  GridLayout1.ItemWidth := 100;
  GridLayout1.ItemHeight := 23;
  for i:= 1 to 7 do
    begin
      B := TButton.Create(Self);
      GridLayout1.AddObject(B);
      B.Text := Format('Button %d', [i]);
      B.Margins.Left := 5;
      B.Margins.Top := 5;
      B.OnClick := AButtonClick;
      //B.Parent := Self;
      //B.Height := 23;
      //B.Width := 100;
      //B.Position.X:=25 + i* 105;
      //B.Position.Y:=70;
    end;
end;

这篇关于Delphi:如何使TButtons 3x3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆