zoukankan      html  css  js  c++  java
  • 【2017-12-06】winfrom 窗体自启最大化,控件自适应

    先将窗体windowstate属性设置为Maximized    



    public partial class Form1 : Form { public Form1() { InitializeComponent(); } //获取所有控件属性(长、宽、位置、字体大小) private void setTag(Control cons) { foreach (Control con in cons.Controls) { con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size; if (con.Controls.Count > 0) setTag(con); label1.Text += con.Tag; } } //设置控件动态大小 private void setControls(float newx, float newy, Control cons) { foreach (Control con in cons.Controls) { string[] mytag = con.Tag.ToString().Split(new char[] { ':' }); float a = Convert.ToSingle(mytag[0]) * newx; con.Width = (int)a; a = Convert.ToSingle(mytag[1]) * newy; con.Height = (int)(a); a = Convert.ToSingle(mytag[2]) * newx; con.Left = (int)(a); a = Convert.ToSingle(mytag[3]) * newy; con.Top = (int)(a); Single currentSize = Convert.ToSingle(mytag[4]) * Math.Min(newx, newy); con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit); if (con.Controls.Count > 0) { setControls(newx, newy, con); } } } private void Form1_Load(object sender, EventArgs e) { setTag(this); float newx = (float)this.Width / 794; //窗体制作时的宽度 float newy = (float)this.Height / 474; //窗体制作时的高度 label1.Text = newx.ToString(); setControls(newx, newy, this); } }
  • 相关阅读:
    Codeforces Round #336 B
    Codeforces Round #336 A
    hiho一下157
    Codeforces Round #420 E
    Codeforces Round #420 C
    Codeforces Round #420 B
    Codeforces Round #420 A
    Codeforces Round #418 C
    Codeforces Round #418 B
    CodeForces 811D Vladik and Favorite Game bfs,模拟
  • 原文地址:https://www.cnblogs.com/qq609113043/p/7992829.html
Copyright © 2011-2022 走看看