source: trunk/Packages/bgracontrols/testbgracontrols/uscaledpi.pas

Last change on this file was 2, checked in by chronos, 5 years ago
File size: 1.0 KB
Line 
1unit uscaledpi;
2
3{$mode objfpc}{$H+}
4
5interface
6
7uses
8 Forms, Graphics, Controls;
9
10procedure HighDPI(FromDPI: integer);
11procedure ScaleDPI(Control: TControl; FromDPI: integer);
12
13implementation
14
15uses BGRABitmap, BGRABitmapTypes;
16
17procedure HighDPI(FromDPI: integer);
18var
19 i: integer;
20begin
21 for i := 0 to Screen.FormCount - 1 do
22 ScaleDPI(Screen.Forms[i], FromDPI);
23end;
24
25procedure ScaleDPI(Control: TControl; FromDPI: integer);
26var
27 i: integer;
28 WinControl: TWinControl;
29begin
30 if Screen.PixelsPerInch = FromDPI then
31 exit;
32
33 with Control do
34 begin
35 Left := ScaleX(Left, FromDPI);
36 Top := ScaleY(Top, FromDPI);
37 Width := ScaleX(Width, FromDPI);
38 Height := ScaleY(Height, FromDPI);
39 //Font.Height := ScaleY(Font.GetTextHeight('Hg'),FromDPI);
40 end;
41
42 if Control is TWinControl then
43 begin
44 WinControl := TWinControl(Control);
45 if WinControl.ControlCount = 0 then
46 exit;
47 for i := 0 to WinControl.ControlCount - 1 do
48 ScaleDPI(WinControl.Controls[i], FromDPI);
49 end;
50end;
51
52end.
Note: See TracBrowser for help on using the repository browser.