ScaleDPI: unit for making Windows 7 High DPI Applications
Original Reporter info from Mantis: lainz
-
Reporter name:
Original Reporter info from Mantis: lainz
- Reporter name:
Description:
This is a procedure like ScaleBy to scale Forms and Controls position and size, it uses ScaleX and ScaleY (http://msdn.microsoft.com/en-us/library/dd464660(v=VS.85).aspx) because those functions reads the system DPI configuration, so the scaling is relative to DPI and works for making Windows 7 High DPI Applications.
Just a procedure ScaleControl(Control: TControl; FromDPI: Integer);
Download and compile the attached file, it contains the scaledpi.pas with the procedure ScaleControl, the project file show how to use the procedure :)
To test if it works change your screen DPI in the Control Panel (additional information how to change your screen DPI at the first msdn link ^^)
Additional information:
In a Form the "FromDPI" value must be defined by the designer (i wish a property in the Object Inspector "FromDPI" or "DesignedDPI" and call ScaleControl when the form is being created automatically :).
const
FromDPI=96; // if you designed the form at 96 dpi (100%).
{ FromDPI=144; if you designed the form at 144 dpi (150%): the procedure scale down the size of the form and controls if you are running in a lower dpi }
then OnCreate event:
if FromDPI <> Screen.PixelsPerInch then begin
ScaleControl(Self,FromDPI);
end;
This unit uses some code used in ScaleBy (http://bugs.freepascal.org/view.php?id=17250) to recursively scale controls inside TPanel and other controls.
Mantis conversion info:
- Mantis ID: 18233
- Version: 0.9.29 (SVN)
- Monitored by: » zaher (Zaher Dirkey)