Skip to main content

TdxForm.ScaleFactorChanged(Integer,Integer) Method

Updates the form and components within it when the scale factor changes.

Declaration

procedure ScaleFactorChanged(M: Integer; D: Integer); virtual;

Parameters

Name Type Description
M Integer

The new scale factor multiplier.

D Integer

The new scale factor denominator.

Remarks

The ScaleFactorChanged procedure is called automatically every time the application accepts the WM_DPICHANGED[1] system message if the Scaled property is set to True. ScaleFactorChanged calls the [UpdateImageLists] procedure to dynamically switch between multiple image lists with bitmap icons that target different DPIs.

For example, you can override the ScaleFactorChanged procedure in a TdxForm class descendant to execute custom actions when the ScaleFactor property value changes. To allow the custom form to switch between DPI-specific image lists, call the UpdateImageLists procedure within a custom ScaleFactorChanged procedure implementation.

Tip

This image list replacement technique is deprecated. We recommend that you use only SVG images as UI icons in projects that target multi-monitor high-DPI environments.

Code Example

The following code example demonstrates a custom ScaleFactorChanged procedure implementation that switches between multiple image lists based on DPI thresholds:

function TMyForm.GetMostSuitableImageList: TcxImageList;
var
  ATargetDPI: Integer;
begin
  ATargetDPI := ScaleFactor.Apply(96);  // Calculates the current DPI
  if ATarget >= 192 then
    Result := ilImages200  // Chooses the icon set designed for 200% DPI
  else if ATargetDPI >= 144 then
    Result := ilImages150  // Chooses the icon set designed for 150% DPI
  else if ATargetDPI >= 120 then
    Result := ilImages125  // Chooses the icon set designed for 125% DPI
  else
    Result := ilImages;  // Chooses the icon set designed for 100% DPI (unscaled)
end;

procedure TMyForm.ScaleFactorChanged(M, D: Integer);
var
  AImageList: Integer;
begin
  AImageList := GetMostSuitableImageList;  // Chooses a suitable replacement image list
  btnBMPGlyph.OptionsImage.Images := AImageList;  // Substitutes the button's image list
  AImageList.GetImage(0, btnBMPGlyph.OptionsImage.Glyph);  // Applies the first image as a button glyph
  btnBMPGlyph.OptionsImage.Glyph.SourceDPI := AImageList.SourceDPI; // Updates the glyph DPI
end;
Footnotes
  1. An application accepts the WM_DPICHANGED system message only if the application manifest includes the permonitor or permonitorv2 item.

See Also