Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

TdxForm.ScaleFactorChanged(Integer,Integer) Method

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

#Declaration

Delphi
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 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 mixed-DPI environments.

#Code Example: Switch Between Bitmap Image Lists Based on DPI

The following code example demonstrates 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