Willy
Willy

Reputation: 10638

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)?

Upvotes: 1

Views: 935

Answers (1)

Reza Aghaei
Reza Aghaei

Reputation: 125187

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.

Upvotes: 1

Related Questions