C# 设计WinForm程序时,有时需要窗体的控件跟随窗体大小等比例变化,满足显示要求,可以参考以下方法:
//控件调整变量
float X;
float Y;
float y;
//窗体加载函数
public frmMain()
{
InitializeComponent();
//窗体大小初始化
X = this.Width;
Y = this.Height;
y = this.ssr.Height;
setTag(this);
}
//控件调整函数
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);
}
}