Hi @Jordan Halgunseth ,
You can refer to the following code to resize the controls' size according to the scaling ratio of the form.
public Form1()
{
InitializeComponent();
x = this.Width;
y = this.Height;
setTag(this);
}
private float x;
private float y;
private void setTag(Control cons)
{
foreach (Control con in cons.Controls)
{
con.Tag = con.Width + ";" + con.Height + ";" + con.Left + ";" + con.Top + ";" + con.Font.Size;
if (con.Controls.Count > 0)
{
setTag(con);
}
}
}
private void setControls(float newx, float newy, Control cons)
{
foreach (Control con in cons.Controls)
{
if (con.Tag != null)
{
string[] mytag = con.Tag.ToString().Split(new char[] { ';' });
con.Width = Convert.ToInt32(System.Convert.ToSingle(mytag[0]) * newx);
con.Height = Convert.ToInt32(System.Convert.ToSingle(mytag[1]) * newy);
con.Left = Convert.ToInt32(System.Convert.ToSingle(mytag[2]) * newx);
con.Top = Convert.ToInt32(System.Convert.ToSingle(mytag[3]) * newy);
Single currentSize = System.Convert.ToSingle(mytag[4]) * newy;
con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
if (con.Controls.Count > 0)
{
setControls(newx, newy, con);
}
}
}
}
private void Form1_ResizeEnd(object sender, EventArgs e)
{
float newx = (this.Width) / x;
float newy = (this.Height) / y;
setControls(newx, newy, this);
}
Best Regards.
Jiachen Li
----------
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.