Board index » delphi » Newbie Q: Max Form Size

Newbie Q: Max Form Size

Just a quick newbie question.  How do I set the maximum dimensions for my
form?  I've come up with a simple solution but it isn't as pretty as I'd
like:

 If Height > 610 then
  Height := 610;
 If Width > 800 then
  Width := 800;

Using this makes the form have a '{*word*221} band' type effect when the user
tries to stretch it farther than its maximum dimensions (it snaps back).
What I'd like is for the form to just stop at its max limit.  How would I do
this?  Thanks for any help.  :)

- David

 

Re:Newbie Q: Max Form Size


In article <7056l6$rj...@holly.prod.itd.earthlink.net>, "David Carvalho"

Quote
<carval...@NOSPAMearthlink.net> writes:
>Just a quick newbie question.  How do I set the maximum dimensions for my
>form?  I've come up with a simple solution but it isn't as pretty as I'd
>like:

> If Height > 610 then
>  Height := 610;
> If Width > 800 then
>  Width := 800;

>Using this makes the form have a '{*word*221} band' type effect when the user
>tries to stretch it farther than its maximum dimensions (it snaps back).
>What I'd like is for the form to just stop at its max limit.  How would I do
>this?  Thanks for any help.  :)

Put this in the public section of the forms declaration:

procedure GetMinMax (var MinMaxMessage: TWMGetMinMaxInfo);
          message WM_GETMINMAXINFO;

put something like this in the OnCreate of the form, the screen .height etc can
be constants but
doing it like this fixes the size relative to the screen. If you do it to
constants you can end up with some odd size at different resolutions

Min_FormHeight:= Screen.Height div 4;
Min_FormWidth:= Screen.Width div 4;
Max_FormHeight:= Screen.Height div 2;
Max_FormWidth:=  Screen.Width div 2;

Hope this helps

Gordon Whittam

http://members.aol.com/gwhit41980/

Re:Newbie Q: Max Form Size


Quote
David Carvalho wrote in message

<7056l6$rj...@holly.prod.itd.earthlink.net>...

Quote
>Just a quick newbie question.  How do I set the maximum dimensions for my
>form?  I've come up with a simple solution but it isn't as pretty as I'd
>like:

> If Height > 610 then
>  Height := 610;
> If Width > 800 then
>  Width := 800;

>Using this makes the form have a '{*word*221} band' type effect when the user
>tries to stretch it farther than its maximum dimensions (it snaps back).
>What I'd like is for the form to just stop at its max limit.  How would I
do
>this?  Thanks for any help.  :)

The answer lies in delving into the Windows API for the
WM_GETMINMAXINFO message. Windows sends this
message to a window that is being resized to request
maximum or minimum sizes.

1. Add the following procedure declaration to the private
section of your form declaration:

private
   :
   procedure WmGetMinMaxInfo(var Msg : TMessage); message WM_GETMINMAXINFO;
   :

2. In the implementation section of the unit, write the body
of the procedure (replace "TForm1" with whatever your form
is called):

procedure TForm1.WmGetMinMaxInfo(var Msg : TMessage);
begin
  inherited;

  PMinMaxInfo(Msg.LParam)^.ptMaxTrackSize.X := 800; //max width
  PMinMaxInfo(Msg.LParam)^.ptMaxTrackSize.Y := 610; //max height
end;

That's it! The details are a little messy - basically the LParam of
the message is a pointer to a MINMAXINFO structure that Windows
has created. We've typecasted the LParam to a pointer to this
structure, and then dereferenced the pointer with "^".

Because Msg is a "var" parameter, we can modify the contents,
and Windows will know our desired dimensions when the message
handler returns.

If you want minimum sizes, use "ptMinTrackSize".

HTH
-
Jeremy Collins
Kansai Business Systems

Other Threads