Limit the size and position of a form while redimensioning  

Send By: Q3 Team
Web : www.q3.nu
Email: dlib@q3.nu
Date: 08/09/00

Tip accessed 583 times

 



If we put a limit to the Width or the Height of the form in the event OnResize
we will see an unpleasant flicker efect in the form.
To avoid it, enough simply with to capture the message TWMGETMINMAXINFO and to treat him with
our procedure.


For example, to fix the dimensions and the position of the form when it is maximzed:

First we capture the message putting this it lines in the private part of the form:


 	type
 	  TForm1 = class(TForm)
 	    procedure FormCreate(Sender: TObject);
 	  private
 	    { Private declarations }
 	    {Esta linea/This line}
 	     procedure mymax(var m: TWMGETMINMAXINFO); message wm_getminmaxinfo;




And we put the procedure that treats the message in the implementation part of the form:


 	procedure TForm1.mymax(var m : TWMGETMINMAXINFO);
 	begin
 	  m.minmaxinfo^.ptmaxsize.x := 300;     {Width/Ancho}
 	  m.minmaxinfo^.ptmaxsize.y := 300;     {Height/Alto}
 	  m.minmaxinfo^.ptmaxposition.x := 10;  {Left/Posicion X}
 	  m.minmaxinfo^.ptmaxposition.y := 10;  {Top/Posicion Y}
 	end;



This will make our form, when being maximized to be of 300x300 and be in Top 10 and Left 10



If what we look for is that the user cannot diminish the size of the form until a limit:


 	procedure TForm1.mymax(var m : TWMGETMINMAXINFO);
 	begin
 	  m.minmaxinfo^.ptMinTrackSize.x := 300;     {Ancho Mínimo/Min Width}
 	  m.minmaxinfo^.ptMinTrackSize.y := 300;     {Alto  Mínimo/Min Height}
 	end;



This will make that the form cannot be made smaller than 300x300 pixels.



If we want it is to put the limit when enlarging it... that is to say, not to allow that the
user makes the form bigger that certain limits:



 	procedure TForm1.mymax(var m : TWMGETMINMAXINFO);
 	begin
 	  m.minmaxinfo^.ptMaxTrackSize.x := 300;     {Ancho mímino/Min Width}
 	  m.minmaxinfo^.ptMaxTrackSize.y := 300;     {Alto Mínimo/Min Height}
 	end;



This will make that the form cannot be enlarged more than 300x300 pixels


Look for in the help file of the Api (win32.hlp) the help for the message WM_GETMINMAXINFO and
you will see all the possibilities that it offers us.


Sent by: DARIO ALVAREZ ARANDA (dalvarez@udesoft.com)

For Delphi4 or later:

   Form1.Constraints.MinHeight:=200;
   Form1.Constraints.MinWidth:=200;
   Form1.Constraints.MaxHeight:=300;
   Form1.Constraints.MaxWidth:=300;




Updated at 07/09/2000