⚠ Deprecated: Legacy
Suggested alternative: AutoScaleHelper
Control Layout Adaptive Resolution Assistant Class for Winform
$ dotnet add package Winform.AutoSizeHelperA Control Layout Adaptive Resolution Assistant Class for Winform.
Design your Form in Form Designer,for example:

Disable the AutoScaleMode property in Form manually. Find Form1.Designer.cs and open it, press Ctrl + F to search string:"AutoScaleMode",then you can see this line:
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
Modify it to System.Windows.Forms.AutoScaleMode.None.
using AutoSizeTools;
namespace XXX{
public partial class Form1 : Form{
AutoSizeHelper helper;
public Form1()
{
InitializeComponent();
helper = new AutoSizeHelper(this);
}
}
}

if we want to dynamically Add a new button which between button2 and button3 by clicking button6, we can achieve this in the following way:
private void button6_Click(object sender, EventArgs e)
{
Button newBtn = new Button();
newBtn.Name = "button7";
newBtn.Location = new Point(568, 12);
newBtn.Size = new System.Drawing.Size(75, 23);
newBtn.Text = "button7";
//apply button6's font to newBtn font
newBtn.Font = new Font(button6.Font.FontFamily, button6.Font.Size);
newBtn.UseVisualStyleBackColor = true;
this.Controls.Add(newBtn);
helper.AddNewControl(newBtn);
helper.UpdateControls();
}
There are some differences in using AutoSizeHelper and AutoSizeHelperEx. When using AutoSizeHelperEx, it should be noted that you need to call the UpdateControls method in the sizechanged event handler of the form.Such like this(this example is from demo--adjust_font):
private void FontForm_SizeChanged(object sender, EventArgs e)
{
Size screenSize = Screen.PrimaryScreen.Bounds.Size;
if (screenSize == new Size(1920,1080))
{
helper.FontAdjustRate = 1.0f;
}
else if (screenSize == new Size(1280, 960))
{
helper.FontAdjustRate = 0.8f;
}
helper.UpdateControls(); // call this method to refresh UI
}
The other uses of AutoSizeHelperEx are consistent with AutoSizeHelper.
For more examples, please see github repository.