Board index » delphi » Form Resize - minimum size of form?

Form Resize - minimum size of form?

Hi,
I've designed a form which mostly aligns to client.  There does come a
time when
some controls overlap, like when the form is resized to be smaller.
What sort of
code do I need to put in the FormResize to limit the smallest that the
form can be
resized to?  I've tried the following, but it doesn't work very well :

procedure TFrmMain.FormResize(Sender: TObject);
begin
     if (btnClear.Left < (chkBVerbose.Left + chkBVerbose.Width + 5) )
then
        FrmMain.Width := FrmMain.Width +1;

     if (FrmMain.Height < 64 ) then
        FrmMain.Height := 64;
end;

Any help gratefully received!!!

TIA,
Dean.
Dean.Kei...@cwb.com

 

Re:Form Resize - minimum size of form?


Hi Dean !

Dean Keigan schrieb:

Quote
> What sort of
> code do I need to put in the FormResize to limit the smallest that the
> form can be
> resized to?  

In D4, you can use the Contraints-property where you can set the min and
max size of a form.

If you use D3 or lower, you should use the WM_GETMINMAXINFO-message like
this:

procedure TForm1.WMGetMinMaxInfo(var Message: TWMGetMinMaxInfo);
{sets Size-limits for the Form}
var
  MinMaxInfo : PMinMaxInfo;
begin
  inherited;
  MinMaxInfo := Message.MinMaxInfo;
  MinMaxInfo^.ptMaxTrackSize.X := 400; // Maximum Width
  MinMaxInfo^.ptMaxTrackSize.Y := 105; // Maximum Height
  MinMaxInfo^.ptMinTrackSize.X := 300; // Minimum Width
  MinMaxInfo^.ptMinTrackSize.Y := 105; // Minimum Height
end;

Don't forget to declare the function in the private-section of your Form
declaration:
    procedure WMGetMinMaxInfo(var Message: TWMGetMinMaxInfo); message
WM_GETMINMAXINFO;

Have fun,

Dets ...

Re:Form Resize - minimum size of form?


Thank you very much!!!  It worked a treat!

Cheers,
D.

Quote
Dets wrote:
> Hi Dean !

> Dean Keigan schrieb:
> > What sort of
> > code do I need to put in the FormResize to limit the smallest that the
> > form can be
> > resized to?

> In D4, you can use the Contraints-property where you can set the min and
> max size of a form.

> If you use D3 or lower, you should use the WM_GETMINMAXINFO-message like
> this:

> procedure TForm1.WMGetMinMaxInfo(var Message: TWMGetMinMaxInfo);
> {sets Size-limits for the Form}
> var
>   MinMaxInfo : PMinMaxInfo;
> begin
>   inherited;
>   MinMaxInfo := Message.MinMaxInfo;
>   MinMaxInfo^.ptMaxTrackSize.X := 400; // Maximum Width
>   MinMaxInfo^.ptMaxTrackSize.Y := 105; // Maximum Height
>   MinMaxInfo^.ptMinTrackSize.X := 300; // Minimum Width
>   MinMaxInfo^.ptMinTrackSize.Y := 105; // Minimum Height
> end;

> Don't forget to declare the function in the private-section of your Form
> declaration:
>     procedure WMGetMinMaxInfo(var Message: TWMGetMinMaxInfo); message
> WM_GETMINMAXINFO;

> Have fun,

> Dets ...

Other Threads