>
> Hello,
>
> I made an application that looks fine when windows is using small fonts, but
> if the user is using large fonts, the form looks bad.
>
> What can I do to solve this problem??..
> I think that maybe the solution is to detect if the user is using large
> fonts and resize the form and the controls, but I am not sure. that this is
> the correct way to do it..
>
> Thanks,
Here’s an earlier post on this popular subject…
==================================================
Hi there for who is interested in this subject!
There were discussions here about problems caused when app is
developed on one system settings and then executed on other.
I played a little bit with this and found out a satisfactory solution
for me…
I designed my app in small fonts (96 DPI) with Scaled = false and
tried to execute it on large fonts (120 DPI) and results were perfect
for what I put on my forms. I thought someone might benefit from what
I have done.
Special care was taken for alignments and anchoring… please try it
yourself. Just call the FixDPI function below after form creation.
yours,
tomi.
[code lang=”delphi”]procedure FixDPI(f: TForm; DesignDPI: integer);
(*
Small/Large system font solution
Have a TForm’s properties Scaled and AutoScroll set to false
and after creating your form call this procedure like:
FixDPI (TForm1, 96) // If you designed in small fonts
Author: Tomislav Kardas, Zagreb, Croatia, Europe
Platform: Delphi 4 C/S
*)
var
ScaleM, ScaleD: integer;
function Scale(x: longint): longint;
begin
result := (x*ScaleM + ScaleD div 2) div ScaleD;
end;
procedure FixControl(c: TControl);
var
x: integer;
p: TWinControl;
fixheight: boolean;
begin
p := c.Parent;
if c.Align <> alNone then begin
// Fixing width
if ((c.Align = alLeft) and (akRight in c.Anchors)) or
((c.Align = alRight) and (akLeft in c.Anchors)) then
c.Width := p.ClientWidth – Scale(p.ClientWidth – c.Width)
else if (c.Align = alLeft) or (c.Align = alRight) then
c.Width := Scale(c.Width);
// Fixing height
if ((c.Align = alTop) and (akBottom in c.Anchors)) or
((c.Align = alBottom) and (akTop in c.Anchors)) then
c.Height := p.ClientHeight – Scale(p.ClientHeight – c.Height)
else if (c.Align = alTop) or (c.Align = alBottom) then
c.Height := Scale(c.Height);
end
else begin
// Fixing width
x := p.ClientWidth – c.Width – c.Left;
if akLeft in c.Anchors then begin
c.Left := Scale(c.Left);
if akRight in c.Anchors then
c.Width := p.ClientWidth – c.Left – Scale(x)
else
c.Width := Scale(c.Width);
end
else if akRight in c.Anchors then begin
c.Width := Scale(c.Width);
c.Left := p.ClientWidth – c.Width – Scale(x);
end
else begin
c.Left := Scale(c.Left);
c.Width := Scale(c.Width);
end;
// Fixing height
fixheight := true;
if (c is TCustomEdit) and not (c is TCustomMemo) then
fixheight := false;
x := p.ClientHeight – c.Height – c.Top;
if akTop in c.Anchors then begin
c.Top := Scale(c.Top);
if fixheight then begin
if akBottom in c.Anchors then
c.Height:= p.ClientHeight – c.Top – Scale(x)
else
c.Height:= Scale(c.Height);
end;
end
else if akBottom in c.Anchors then begin
if fixheight then
c.Height := Scale(c.Height);
c.Top := p.ClientHeight – c.Height – Scale(x);
end
else begin
c.Top := Scale(c.Top);
if fixheight then
c.Height := Scale(c.Height);
end;
end;
end;
procedure FixControls(c: TWinControl);
var
i: integer;
begin
for i := 0 to c.ControlCount – 1 do
if c.Controls[i].Owner = f then begin
FixControl(c.Controls[i]);
if c.Controls[i] is TWinControl then
FixControls(TWinControl(c.Controls[i]));
end;
end;
begin
if DesignDPI <> Screen.PixelsPerInch then begin
ScaleM := Screen.PixelsPerInch;
ScaleD := DesignDPI;
f.ClientWidth := Scale(f.ClientWidth);
f.ClientHeight := Scale(f.ClientHeight);
FixControls(f);
end;
end;
[/code]
[tags]Delphi, Forms[/tags]
0 Kommentare zu “Small Fonts / Large Fonts (3)”