Completed
Last Updated: 04 May 2022 07:29 by ADMIN
Release R2 2022
Iprel
Created on: 24 Nov 2021 10:08
Category: Form
Type: Bug Report
0
RadForm: RadControls inside a UserControl added at design time are scaled twice

To reproduce:

  1. Set your monitor DPI to 200%(or any order value different from 100%). You need to Log off(or restart) in order to apply correctly the new DPI settings.
  2. Create a UserControl with some RadControls inside.
  3. Add the UserControl at design time as a child control to a RadForm.
  4. Run the RadForm and you will see that the controls inside the user control are scaled twice.

Workaround:

In the OnLoad method of RadForm do through all nested RadControls inside the UserControl and downscale them to the same DPI as the RadForm.

public class RadForm1 : RadForm
{
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        SizeF dpiScaleFactor = RootElement.DpiScaleFactor;
        FixDpiScaling(this.Controls, dpiScaleFactor);
    }

    private void FixDpiScaling(Control.ControlCollection controls, SizeF dpiScaleFactor)
    {
        foreach (Control item in controls)
        {
            RadControl radControl = item as RadControl;
            if (radControl != null)
            {
                SizeF dpi2 = radControl.RootElement.DpiScaleFactor;
                if (dpiScaleFactor.Width != dpi2.Width)
                {
                    SizeF fixDpiCoefficient = new SizeF(dpiScaleFactor.Width / dpi2.Width, dpiScaleFactor.Height / dpi2.Height);
                    radControl.Scale(fixDpiCoefficient);
                }
            }

            FixDpiScaling(item.Controls, dpiScaleFactor);
        }
    }
}

0 comments