This is a migrated thread and some comments may be shown as answers.

RadLabel.MaximumSize on High DPI

2 Answers 300 Views
Label
This is a migrated thread and some comments may be shown as answers.
Jeremy
Top achievements
Rank 1
Jeremy asked on 12 Dec 2018, 05:24 AM

Hello.
I try to display long description text with nice word wrapping using RadLabel
To do that I set AutoSize=true but control Width of RadLabel setting MaximumSize.
I set the maximum size and recalculate it every time Form's size changes.

Everything works fine until you change the DPI settings in the system. 
When you do this and change MaximumSize property at runtime my value will be multiplied by the scaling value.
And since I use form size (which is already scaled) I got doubled scale.
For example if I set scaling 150% my value be multiplied by 1.5.

Below I gave examples of my code and screenshots from different DPI. 

100% https://clip2net.com/s/3YxZaSZ
150% https://clip2net.com/s/3YxZom6
200% https://clip2net.com/s/3YxZees

I use Telerik 2018.3.1016.20 with .Net 3.5 
I very much rely on your help and advice.

using System;
using System.Drawing;
using Telerik.WinControls.UI;
 
namespace DesignExamples.BugsForTelerik
{
    public class Form1 : RadForm
    {
        private RadLabel radLabel1;
        private RadLabel radLabel2;
 
        public Form1()
        {
            InitializeComponent();
        }
 
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.radLabel1 = new Telerik.WinControls.UI.RadLabel();
            this.radLabel2 = new Telerik.WinControls.UI.RadLabel();
            ((System.ComponentModel.ISupportInitialize)(this.radLabel1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.radLabel2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
            this.SuspendLayout();
            //
            // radLabel1
            //
            this.radLabel1.Dock = System.Windows.Forms.DockStyle.Top;
            this.radLabel1.Location = new System.Drawing.Point(0, 0);
            this.radLabel1.Name = "radLabel1";
            this.radLabel1.Size = new System.Drawing.Size(2054, 18);
            this.radLabel1.TabIndex = 0;
            this.radLabel1.Text = resources.GetString("radLabel1.Text");
            //
            // radLabel2
            //
            this.radLabel2.Dock = System.Windows.Forms.DockStyle.Top;
            this.radLabel2.Location = new System.Drawing.Point(0, 18);
            this.radLabel2.Name = "radLabel2";
            this.radLabel2.Size = new System.Drawing.Size(81, 18);
            this.radLabel2.TabIndex = 1;
            this.radLabel2.Text = "MaximumSize: ";
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(504, 270);
            this.Controls.Add(this.radLabel2);
            this.Controls.Add(this.radLabel1);
            this.Name = "Form1";
            //
            //
            //
            this.RootElement.ApplyShapeToControl = true;
            this.Text = "Form1";
            this.Resize += new System.EventHandler(this.OnResize);
            ((System.ComponentModel.ISupportInitialize)(this.radLabel1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.radLabel2)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();
 
        }
 
        private void OnResize(object sender, EventArgs e)
        {
            var maximumSize = new Size(Width - radLabel1.Margin.Horizontal, 0);
            radLabel1.MaximumSize = maximumSize;
            radLabel2.Text = $@"maximumSize: {maximumSize}
radLabel1.MaximumSize: {radLabel1.MaximumSize}";
        }
    }
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 12 Dec 2018, 08:39 AM
Hello Jeremy,

The MaxSize and other size properties need to be scaled when running on HDPI. This is expected and you need to descale the size. We have built-in methods for this. Here is what you can use for this case:
radLabel1.MaximumSize = TelerikDpiHelper.ScaleSize(maximumSize, new SizeF(1f / this.RootElement.DpiScaleFactor.Width, 1f / this.RootElement.DpiScaleFactor.Height));

This will work for 100% as well.

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Jeremy
Top achievements
Rank 1
answered on 19 Dec 2018, 11:15 AM
Thanks for your help, it worked for me. 
Tags
Label
Asked by
Jeremy
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Jeremy
Top achievements
Rank 1
Share this question
or