Delphi:每个控件之间的TFlowPanel边距

Den*_* F. 7 delphi controls margin flowpanel

我正在使用TFlowPanel,在运行时我正在创建一个可变数量的控件(在本例中为TButton).我想在每个控件之间创建一个边距,但它还没有工作.

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
  LButton: TButton;
begin
  for i := 0 to 10 do
  begin
    LButton := TButton.Create(flwpnl1); // flwpnl1 is the TFlowPanel
    LButton.Parent  := flwpnl1;
    LButton.Height  := 20;
    LButton.Caption := Format('Status%d', [i]);
    LButton.Margins.Left   := 20;
    LButton.Margins.Top    := 20;
    LButton.Margins.Right  := 20;
    LButton.Margins.Bottom := 20;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

例

有什么想法吗?

关心和感谢,丹尼斯

小智 5

您需要将 AlignWithMargins 设置为 true,因此在您的代码中将是:

LButton.AlignWithMargins := true;
Run Code Online (Sandbox Code Playgroud)