Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi - Maximize a form to a particular screen

Quite a simple one i would think, but i need to be able to Maximize a form to a particular screen. Cant seem to find any Delphi specific info.

I can remember the forms position over subsequent application loads. However, when i restore the position, then call WindowState := wsMaximized, the form moves to the other screen! (i do have other forms also visible on that screen - it appears its maximizing to the 'active screen')

So i need a function like so:

procedure Maximize(const aScreenIndex : Integer);
begin
 if aScreenIndex < Screen.MonitorCount then
   //Maximize to that screen
end;
like image 414
Simon Avatar asked Jun 16 '11 07:06

Simon


2 Answers

Intercept the WM_GETMINMAXINFO message and adjust the coordinates inside its MINMAXINFO structure as needed.

like image 180
Remy Lebeau Avatar answered Sep 30 '22 13:09

Remy Lebeau


Set Form.Position to poDesigned at design time In Form.FormShow or your Maximize procedure:

procedure Maximize(const aScreenIndex : Integer);
begin
  if aScreenIndex < Screen.MonitorCount then
  begin 
   //Maximize to that screen
    Myform.Left := screen.Monitors[aScreenIndex ].Left;
    Myform.WindowState := wsMaximized;
  end; 
end;
like image 44
Despatcher Avatar answered Sep 30 '22 14:09

Despatcher