ScaleHelperGetScale(Graphics) Method

Gets the current scale factor of the specified Graphics object.

Definition

Namespace: KGySoft.WinForms
Assembly: KGySoft.WinForms (in KGySoft.WinForms.dll) Version: 5.0.1
C#
public static PointF GetScale(
	this Graphics graphics
)

Parameters

graphics  Graphics
The Graphics object for which the scale factor is requested.

Return Value

PointF
A PointF representing the scale factor of the graphics object, where X and Y are the horizontal and vertical scale factors, respectively.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Graphics. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

If the process is not per-monitor DPI aware, the result is based on the DpiX and DpiY properties of the graphics object. Otherwise, it attempts to retrieve the scaling of the window that the graphics object is associated with. If no such window is found, it falls back to the DpiX and DpiY properties.

  Note

Always try to use the GetScale(Control) overload in the first place. If the graphics object is not associated with a control (e.g. when it is created from a bitmap), it may return unexpected results.

See Also