效果图如下 第一张是放大后的 第二张是缩小后的
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/557c8ac2ba91aca274d631caacd9bb7b.png)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/4f30714cd0be1503b3e779a85f5fc45c.png)
#region 改变窗体大小
public 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);
}
}
}
public void setControls(float newx, float newy, Control cons)
{
try
{
//遍历窗体中的控件,重新设置控件的值
foreach (Control con in cons.Controls)
{
//获取控件的Tag属性值,并分割后存储字符串数组
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);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
#endregion
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0586bd04bcb74bbc7ad4b688554ed8d7.png)
有任何不懂的问题请留言,超过2小时请私聊QQ:2773938492