C#根据屏幕尺寸大小重新定位控件大小和位置
float floScreenProportion = (float)Screen.PrimaryScreen.Bounds.Width / (float)240.0; CPublicParameters.P_RedineControlLocationAndSize(this, floScreenProportion);
/// <summary> /// 按照屏幕尺寸自适应空间大小和位置。floScreenProportion为:屏幕尺寸/当前设计尺寸 /// 比如当前设计尺寸为240,Screen.PrimaryScreen.Bounds.Width为获取的实际屏幕尺寸 /// floScreenProportion = (float)Screen.PrimaryScreen.Bounds.Width / (float)240.0; /// </summary> /// <param name="parent"></param> /// <param name="floScreenProportion"></param> public static void P_RedineControlLocationAndSize(Control parent, float floScreenProportion) { foreach (Control control in parent.Controls)//遍历Form上的所有控件 { control.Width = (int)(floScreenProportion * control.Width); control.Location = new Point((int)(floScreenProportion * (float)control.Location.X), control.Location.Y); if (control.Controls.Count > 0) { P_RedineControlLocationAndSize(control,floScreenProportion); } } }
/// <summary> /// 按照屏幕尺寸自适应空间大小和位置。floScreenProportion为:屏幕尺寸/当前设计尺寸 /// 比如当前设计尺寸为240,Screen.PrimaryScreen.Bounds.Width为获取的实际屏幕尺寸 /// floScreenProportion = (float)Screen.PrimaryScreen.Bounds.Width / (float)240.0; /// </summary> /// <param name="parent"></param> /// <param name="floScreenProportion"></param> public static void P_RedineControlLocationAndSize(Control parent, float floScreenProportion) { foreach (Control control in parent.Controls)//遍历Form上的所有控件 { control.Width = (int)(floScreenProportion * control.Width); control.Location = new Point((int)(floScreenProportion * (float)control.Location.X), control.Location.Y); if (control.Controls.Count > 0) { P_RedineControlLocationAndSize(control,floScreenProportion); } } }
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。