form分辨率

近期作项目时,遇到开发的winform在本身电脑上能够正常显示,共享到其余电脑就事儿不能显示了:函数

【转载自:http://blog.csdn.net/lcawen88/article/details/8989332】this

1.当两个电脑分辨率相同时,没法显示彻底,请检查form的autoscalemode属性是否为none,并设为none.net

2.分辨率不一样时,可直接在form的构造函数中调用初始化函数以后, 加上一句AutoReSizeForm. SetFormSize(this);(对于自定义控件usercontrol也适用)orm

public class AutoReSizeFormblog

    {
        static float SH
        {
            get
            {
                return (float)Screen.PrimaryScreen.Bounds.Height / Properties.Settings.Default.Y;
            }
        }
        static float SW
        {
            get
            {
                return (float)Screen.PrimaryScreen.Bounds.Width / Properties.Settings.Default.X;
            }
        }




        public static void SetFormSize(Control fm)
        {
            fm.Location = new Point((int)(fm.Location.X * SW), (int)(fm.Location.Y * SH));
            fm.Size = new Size((int)(fm.Size.Width * SW), (int)(fm.Size.Height * SH));
            fm.Font = new Font(fm.Font.Name, fm.Font.Size * SH,fm.Font.Style,fm.Font.Unit,fm.Font.GdiCharSet,fm.Font.GdiVerticalFont);
            if (fm.Controls.Count!=0)
            {
                SetControlSize(fm);
            }
        }


        private static void SetControlSize(Control InitC)
        {
            foreach (Control c in InitC.Controls)
            {
                c.Location = new Point((int)(c.Location.X * SW), (int)(c.Location.Y * SH));
                c.Size = new Size((int)(c.Size.Width * SW), (int)(c.Size.Height * SH));
                c.Font = new Font(c.Font.Name, c.Font.Size * SH, c.Font.Style, c.Font.Unit, c.Font.GdiCharSet, c.Font.GdiVerticalFont);
                if (c.Controls.Count != 0)
                {
                    SetControlSize(c);
                }
            }
        }
    } 开发

相关文章
相关标签/搜索