How to Support "Large Fonts" / "Custom DPI" in Delphi Applications

99% of Delphi applications I have seen, do not support Large Fonts, or support it very badly. There is a Scaled property in TForm, people think it is about to scale the form in case of non-default DPI setting, but it is just not working properly.

Below code scales TForm the correct way:

procedure TForm1.FormCreate(Sender: TObject);
begin   
  Assert(not Scaled, 'TForm.Scaled property sucks, you should set it to False!');   
  if Screen.PixelsPerInch <> PixelsPerInch then
  begin     
    ScaleBy(Screen.PixelsPerInch, PixelsPerInch);   
  end; 
end;

Delphi stores design-time DPI of a form in PixelsPerInch property. This code handles scaling correctly even if some forms are designed in 96 DPI, and some forms in 120 DPI.

Comments

Large fonts

THe problem is that DPI for small and large fonts are the same (96). Medium is different (120). So if some controls are off the screen large fonts, it won't scale, because 96/96 = 1

Post new comment

The content of this field is kept private and will not be shown publicly.