Mastodon
Programmierung

Small Fonts / Large Fonts (2) – FormScaler

In article <3aaefd89_2@dnews>, William Meyer wrote:

> Small fonts/large fonts is a problem without a clean solution. The
> suggestion will be to develop at large fonts, and the result will work ok on
> small fonts, but it looks funny to me. I’ve toyed with actually designing
> two sets of forms, and loading them based on the font set in use at runtime.

I develop with small fonts and ‘Scaled’ set to false. When I’m doing
dialog-box style forms I drop a TFormScaler component on the form. It seems
to work…

Here’s TFormScaler – it’s quite simple!

file://———————————————————————
[code lang=”delphi”]unit cmpFormScaler;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
TFormScaler = class(TComponent)
private
fScaled : Boolean;
fDivisor : Integer;
fMultiplier : Integer;
protected
procedure Loaded; override;
public
property M : Integer read fMultiplier;
property D : Integer read fDivisor;
{ Public declarations }
published
{ Published declarations }
end;

implementation

const
SmallFontsI = 454;

{ TFormScaler }

procedure TFormScaler.Loaded;
var
frm : TForm;
s : string;
c : TCanvas;
begin
inherited;
if not (csDesigning in ComponentState) and not fScaled then
begin
fScaled := True;
if Owner is TForm then
begin
frm := TForm (Owner);
frm.Scaled := False;

c := TCanvas.Create;
c.Handle := GetDC (HWND_DESKTOP);

try
s :=
‘ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-=+_)(*&^%$£”!’
;
fMultiplier := c.TextWidth (s);

fDivisor := SmallFontsI;
frm.ScaleBy (fMultiplier, fDivisor);
finally
ReleaseDC (HWND_DESKTOP, c.Handle);
c.Free
end
end
end
end;

end.
[/code]

[tags]Delphi, Forms[/tags]

0 Kommentare zu “Small Fonts / Large Fonts (2) – FormScaler

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.