控件最大化 ,網上找回來的,基本上都測試了,應該可行,不過效果有點不佳:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| 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)); } }
private void Form1_Load(object sender, EventArgs e) { autoScale(this); }
|