Hello, I've a problem with a procedure that I use to resize at runtime the form of a projects, in order to adapt them to the screen resolution if major of the base resolution 1024*768.
procedure AutoScaleForm(var MyForm: TForm; const MyScale: Double; const MyOpt: SmallInt = 0);
var
i: LongInt;
begin
if (MyOpt = 0) then begin
case FormShowType of //FormShowType is a parameter in order to set the BorderStyle property
1: begin
MyForm.BorderStyle := bsDialog;
MyForm.WindowState := wsNormal;
MyForm.AutoScroll := False;
end;
2: begin
MyForm.BorderStyle := bsSingle;
MyForm.WindowState := wsNormal;
MyForm.AutoScroll := True;
end;
3: begin
MyForm.BorderStyle := bsSingle;
MyForm.WindowState := wsMaximized;
MyForm.AutoScroll := True;
end;
4: begin
MyForm.BorderStyle := bsSingle;
MyForm.WindowState := wsMinimized;
MyForm.AutoScroll := True;
end;
5: begin
MyForm.BorderStyle := bsSizeable;
MyForm.WindowState := wsNormal;
MyForm.AutoScroll := True;
end;
6: begin
MyForm.BorderStyle := bsSizeable;
MyForm.WindowState := wsMaximized;
MyForm.AutoScroll := True;
end;
7: begin
MyForm.BorderStyle := bsSizeable;
MyForm.WindowState := wsMinimized;
MyForm.AutoScroll := True;
end;
else begin
//Default, no changes of BorderStyle
end;
end;
end;
//Scale form
if (FormAutoConf = 0) then exit; //Parameter to choose if do scale form
if ((MyScale > 1) or (FormScaleWide > 1)) then begin //Scale form to do
With MyForm do begin
if (FormWideConf > 1) then begin
//Wide screen
Width := Round(Width * MyScale * FormWideConf);
end
else begin
Width := Round(Width * MyScale);
end;
if (Width > MaxFrmWidth) and (MaxFrmWidth > 1024) and (MaxFrmHeight > 768) then Width := MaxFrmWidth; //Max width
Height := Round(Height * MyScale);
if (Height > MaxFrmHeight) and (MaxFrmWidth > 1024) and (MaxFrmHeight > 768) then Height := MaxFrmHeight; //Max Height
for i := 0 to ComponentCount - 1 do begin
//1. Components
if (Components[i] is TControl) then with (Components[i] as TControl) do begin
if (FormWideConf > 1) then begin
Width := Round(Width * MyScale * FormWideConf);
end
else begin
Width := Round(Width * MyScale);
end;
Height := Round(Height * MyScale);
Top := Round(Top * MyScale);
if (FormWideConf > 1) then begin
Left := Round(Left * MyScale * FormWideConf);
end
else begin
Left := Round(Left * MyScale);
end;
end;
end;
end;
The code works good on Lazarus 0.9.28.2 on all platforms, either if the forms are bsDialog, bsSingle or bsSizeable.
With Lazarus 1.0.10/12 the forms are always corretly resized on Windows (Win32), on Linux/GTK2 the forms are not resized if BorderStyle = bsDialog and are only horizontal resized if BorderStyle = bsSingle. With BorderStyle = bsSizeable the code works good also on Linux/GTK2.
The components are instead correctly resized.
All forms have a TPanel, insede the TPanele the are the components.
Have you an advice? Or must I report a bug?
Best regards,
Stefano