您的位置:首页 > 其它

MFC对话框控件随对话框的大小变化

2015-11-03 23:31 267 查看
//控件随窗体自动缩放
string[] tmp = new string[2];

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));
}
使用该代码注意事项:1,此段代码基本通用。2,此段代码写在窗体的加载事件中。3,若窗体需要缩小,请再写在窗体的SizeChanged事件中。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: