C# 窗口应用程序界面拉伸
发布日期:2021-05-10 10:50:34 浏览次数:20 分类:精选文章

本文共 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;
    }
  • ���������������������������������������������������������������������������������������������������������������������������������������������������������������

    ������

    ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

    上一篇:WinForm事件中的Object sender和EventArgs e参数
    下一篇:.mpp文件在线打开网址

    发表评论

    最新留言

    不错!
    [***.144.177.141]2025年04月03日 11时57分15秒