New to Telerik UI for WinForms? Download free 30-day trial

Scale Controls Manually

Description

You need to manually scale the controls. This is needed when you are using the standard .NET form which is not scaling the Telerik UI for WinForms controls. Or you want to use the build-in scaling mechanism to enlarge the controls dynamically.

Solution

Use the Scale method to scale the controls. You can check the current DPI settings in the code as well.

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
     ScaleChildControls();
}

public void ScaleChildControls()
{
    if (TelerikHelper.IsWindows8OrLower || TelerikHelper.IsWindows10CreatorsUpdateOrHigher)
    {

        Screen showScreen = Screen.FromControl(this);
        SizeF scale = NativeMethods.GetMonitorDpi(showScreen, NativeMethods.DpiType.Effective);
        foreach (var item in this.Controls)
        {
            if (item is RadControl)
            {
                var control = item as RadControl;
                if (scale != control.RootElement.DpiScaleFactor)
                {
                    scale = TelerikDpiHelper.ScaleSizeF(scale, new SizeF(1f / control.RootElement.DpiScaleFactor.Width, 1f / control.RootElement.DpiScaleFactor.Height));
                    control.Scale(scale);
                }
            }
        }
    }
}
In this article