CSDN博客

img jevinmeng

控件随窗体自动缩放大小(c#2005)

发表于2008/9/28 21:53:00  342人阅读

 /// <summary>
/// 控件随窗体自动缩放
/// </summary>
/// <param name="frm"></param>
public static void AutoScale(Form frm)
{
frm.Tag = frm.Width.ToString() "," frm.Height.ToString();
frm.SizeChanged = new EventHandler(frm_SizeChanged);
}

static void frm_SizeChanged(object sender, EventArgs e)
{
string[] tmp = ((Form)sender).Tag.ToString().Split(',');
float width = (float)((Form)sender).Width / (float)Convert.ToInt16(tmp[0]);
float heigth = (float)((Form)sender).Height / (float)Convert.ToInt16(tmp[1]);

((Form)sender).Tag = ((Form)sender).Width.ToString() "," ((Form)sender).Height;

foreach (Control control in ((Form)sender).Controls)
{
control.Scale(new SizeF(width, heigth));

}
}
0 0

相关博文

我的热门文章

img
取 消
img