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

TdxCustomForm.ScaleFactor Property

Returns the form’s scale factor.

#Declaration

Delphi
property ScaleFactor: TdxScaleFactor read;

#Property Value

Type Description
TdxScaleFactor

The scale factor for the current monitor DPI.

#Remarks

The ScaleFactor property value changes every time your application accepts the WM_DPICHANGED[1] system message. You can use this property to obtain the current scale factor or call any of the ScaleFactor.Apply functions to apply the scale factor to custom-drawn UI elements within the form.

#Code Example: Scale Custom Geometry

The following code example demonstrates an OnCustomDraw event handler of a TcxButton component that draws a button with custom scaled geometry:

procedure TMyForm.btnColorCustomDraw(Sender: TObject; ACanvas: TcxCanvas;
          AViewInfo: TcxButtonViewInfo; var AHandled: Boolean);
var
  AColorBoxOffset, ALineWidth: Integer;
  AColorBoxRect: TRect;
begin
  AViewInfo.Painter.LookAndFeelPainter.DrawScaledButton(ACanvas, AViewInfo.Bounds, '', AViewInfo.State, ScaleFactor);
  ALineWidth := ScaleFactor.Apply(1);  // Applies the form's scale factor to the line width
  AColorBoxOffset := ScaleFactor.Apply(6);  // Applies the form's scale factor to the box offset
  AColorBoxRect := cxRectInflate(AViewInfo.Bounds, -AColorBoxOffset);
  ACanvas.FrameRect(AColorBoxRect, clBlack, ALineWidth);  // Draws the red square's outline
  AColorBoxRect := cxRectInflate(AColorBoxRect, -ALineWidth);  // Fits the color-filled square into the outline
  ACanvas.FillRect(AColorBoxRect, clRed);  // Fills the outline with the red color
  AHandled := True;
end;
Footnotes
  1. An application accepts the WM_DPICHANGED system message only if the application manifest includes the permonitor or permonitorv2 item.

See Also