Skip to main content

TdxForm.ScaleFactor Property

Returns the form’s scale factor.

Declaration

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 the ScaleFactor.Apply function to apply the scale factor to custom-drawn UI elements within the form.

Code Example

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