简体   繁体   中英

How to force Visual Studio Designer to emit AutoScaleDimensions set to (6F, 13F) within the InitializeComponent function

I have a System.Windows.Forms.UserControl. I have observed that Visual Studio Designer puts the following two lines (among others) within the InitializeComponent function:

this.AutoScaleDimensions = new System.Drawing.SizeF(192F, 192F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

Is there any way from the Designer to tell Visual Studio Designer to put the following line instead of (192F, 192F)?

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

I have looked at the UserControl properties from the designer and I am not able to see what is the property that makes VS Designer to put that line (6F, 13F). So how can I force VS Designer to put (6F, 13F) instead of (192F, 192F)?

You need to set the AutoScaleMode to Dpi , then you can set your custom AutoScaleDimensions :

public partial class UserControl1 : UserControl
{
    public UserControl1()
    {
        InitializeComponent();
        this.AutoScaleMode = AutoScaleMode.Dpi;
        this.AutoScaleDimensions = new SizeF(192, 192);
    }
}

By default the automatic scaling of the control is Font and as soon as the font of the control is set (changed) the value of AutoScaleDimensions will reset.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM