While this works exactly for the old screen resolutions which were all more or less in proportion there is nothing which will resize screens properly for the newer stretched screens, eg. for 1280×960 and 1280×1024. The min ratio calculated is scrx / screenx = 1 so the form stays with original measurements.


Calling this procedure from the form's OnActivate event will resize the form in proportion to the screen resolution – I do my programming on resolution 1280×768 hence the constants – once the form height and width has been calculated it can then be centred.

While this works exactly for the old screen resolutions which were all more or less in proportion there is nothing which will resize screens properly for the newer stretched screens, eg. for 1280×960 and 1280×1024. The min ratio calculated is scrx / screenx = 1 so the form stays with original measurements.



uses
   math,windows;

 const
   screenx = 1280 ;
   screeny = 768 ;

 procedure tform1.autosizeall ;
 var
   scrx,scry, k:integer ;
   ratio:double;
 begin
   scrx:= GetSystemMetrics(SM_CXSCREEN);  {finds screen resolution x value}
   scry:= (GetSystemMetrics(SM_CYSCREEN));  {finds screen resolution y value}

   ratio:=min(scrx/screenx,scry/screeny);
   {takes the smaller ratio and makes sure you dont make the window 
    too big for the screen}

   scaleby(trunc(ratio* 100 ), 100 );
   {scales all controls and attempts to place them in the correct position}

   {to centre the form on the screen}
   form1.Left:=centreleft(form1.width);
   form1.Top:=centretop(form1.Height) ;

 end ; 


Bu kod iki işleve atıfta bulunur:  ölçeklendirme ve merkezleme . Bunlar şu şekilde tanımlanmıştır:


function centreleft(fw:integer):integer;
   {calculates the form.left}
 var
   smcx:integer;
 begin
   smcx:=GetSystemMetrics(SM_CXSCREEN);
   centreleft:=(smcx-fw) div 2 ;
 end ;

 function centretop(fh:integer):integer;
   {calculates the form.top}
 var
   smcy:integer;
 begin
   smcy:=GetSystemMetrics(SM_CYSCREEN);
   centtop:=(smcy-fh) div 2 ;
 end ; 


Program kullanıcının ekran çözünürlüğüne göre yeniden boyutlandırılmış olur.