
本文共 3334 字,大约阅读时间需要 11 分钟。
������������C#������������������������������������������������
���������C#���������������������������������������������������������������������������������������������������������������������������������������������������������
������������������������
���������������������������������������������������������������������������"FormBorderStyle"���������Fixed3D���FixedDialog���FixedSingle���FixedToolWindow���������������������������������������������������
���������������������������
������������������������������������������������������������������
���������������������������������������������������������������������������������������Tag������������
���������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������������������������������
������������������
���������������������������������������������������������
public Form1(){ InitializeComponent(); x = this.Width; y = this.Height; setTag(this);}private float x, y;
������ resize ���������������
private void Form1_Resize(object sender, EventArgs e){ float currentWidth = this.Width; float currentHeight = this.Height; float scale = (currentWidth / x) != 0 ? currentWidth / x : 1.0f; setControls(scale, this);}
������ adjustment ���������������������������������������
private void setControls(float scale, Control parent){ foreach (Control con in parent.Controls) { // ������������������������������ if (con.Controls.Count > 0) setControls(scale, con); // ��������������������������� if (con.Tag != null) { string[] attributes = con.Tag.ToString().Split(';'); con.Width = (int)(Convert.ToSingle(attributes[0]) * scale); con.Height = (int)(Convert.ToSingle(attributes[1]) * scale); con.Left = (int)(Convert.ToSingle(attributes[2]) * scale); con.Top = (int)(Convert.ToSingle(attributes[3]) * scale); // ������������������ float fontSize = Convert.ToSingle(attributes[4]) * scale; con.Font = new Font(con.Font.Name, fontSize, con.Font.Style, con.Font.Unit); } }}
������ setTag ������������������������������������
private void setTag(Control control){ if (control.Controls.Count > 0) setTag(control); // ������������������������������������������������������ if (control.Tag == null) control.Tag = string.Empty; string width = control.Width.ToString(); string height = control.Height.ToString(); string left = control.Left.ToString(); string top = control.Top.ToString(); string fontSize = control.Font.Size.ToString() + ";"; string combined = width + ";" + height + ";" + left + ";" + top + fontSize; control.Tag = combined;}
���������������������������������������������������������������������������������������������������������������������������������������������������������������
������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
