delphi 怎么限制窗口大小?允许用户更改大小但有限制

2025-02-25 12:50:44
推荐回答(2个)
回答1:

procedure TForm1.FormCreate(Sender: TObject);
begin
//最大限制
Constraints.MaxHeight := 400;
Constraints.MaxWidth := 400;
//最小限制
Constraints.MinHeight := 200;
Constraints.MinWidth := 200;
end;
或直接修改窗体的这个属性也可以。

回答2:

procedure TForm1.FormResize(Sender: TObject);
begin
if Self.Width > 420 then Self.Width := 420;
if Self.Height > 240 then Self.Height := 240;
end;