09-08-2021, 11:11 PM
Hi Mike
Sounds as though you are doing the form sizing in the OnShow or as an "after show" event.
The way I handle the sizing is to call my RestoreWindowPlacement routine in the FormCreate event.
Obviously, for this to work, you need to save the necessary screen settings in your FormClose event!
My code is in Delphi but I'm sure you can work it out/adapt to suit your code.
Cheers
Geoff
Sounds as though you are doing the form sizing in the OnShow or as an "after show" event.
The way I handle the sizing is to call my RestoreWindowPlacement routine in the FormCreate event.
Obviously, for this to work, you need to save the necessary screen settings in your FormClose event!
My code is in Delphi but I'm sure you can work it out/adapt to suit your code.
Cheers
Geoff
Code:
// The Prefix is so that I can use the routine to restore any form (and not just the main one).
// The routine does nothing if any of the registry values are invalid i.e. the program will use the form design values
// UsePPI is an input and allows you to ignore the settings if the screen resolution has changed
procedure TMainForm.RestoreWindowPlacement( AForm: TForm; Const Prefix: string; UsePPI: boolean);
Var
bad: boolean;
function ReadInteger( Name: string; Max: integer): integer;
var
str: string;
begin
str:= DataManager.GetKeyedString( Name ); // this is just getting a value from the registry (I use a .ini file)
if IsNumeric( str, 0, Max) then
Result:= StrToInt( str ) else
begin
bad:= true;
Result:= -1;
end;
end;
Var
Rect: TRect;
FullScreen: integer;
OldPPI : integer;
begin
bad:= false;
Rect.Top := ReadInteger( Prefix + 'Top' , Screen.WorkAreaHeight ); // args are "registry name", "screen variable"
Rect.Left := ReadInteger( Prefix + 'Left' , Screen.WorkAreaWidth );
Rect.Bottom := ReadInteger( Prefix + 'Height' , Screen.WorkAreaHeight );
Rect.Right := ReadInteger( Prefix + 'Width' , Screen.WorkAreaWidth );
if (AForm.BorderIcons - [biMinimize, biMaximize] ) <> AForm.BorderIcons then
FullScreen := ReadInteger( Prefix + 'Maximized', 1 ) else
FullScreen := 0;
if usePPI then
OldPPI := ReadInteger( Prefix + 'PixelsPerInch', 999) else
OldPPI := PixelsPerInch;
if bad or (OldPPI <> PixelsPerInch) then
exit;
Rect.Bottom := Rect.Bottom + Rect.Top;
Rect.Right := Rect.Right + Rect.Left;
// Make sure the window is entirely visible on the screen
if (Rect.Right > Screen.WorkAreaWidth) then begin
Dec(Rect.Left, (Rect.Right - Screen.WorkAreaWidth));
Rect.Right := Screen.WorkAreaWidth;
end;
if (Rect.Bottom > Screen.WorkAreaHeight) then begin
Dec(Rect.Top, (Rect.Bottom - Screen.WorkAreaHeight));
Rect.Bottom := Screen.WorkAreaHeight;
end;
AForm.BoundsRect := Rect;
if FullScreen=1 then
AForm.WindowState := wsMaximized;
end;
Samsung Galaxy Tab A6