• C#控件根据窗体改变大小


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace WindowsHttpListener
    {
        public partial class FrmSize : Form
        {
            public FrmSize()
            {
                InitializeComponent();
            }

            private float X, Y;
            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);
                }
            }

            private void FrmSize_Load(object sender, EventArgs e)
            {
                this.Resize += new EventHandler(FrmClinicalTV_Resize);

                X = this.Width;
                Y = this.Height;
                setTag(this);
            }

            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]) * 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 FrmClinicalTV_Resize(object sender, EventArgs e)
            {
                float newx = (this.Width) / X;
                float newy = this.Height / Y;
                setControls(newx, newy, this);
            }
        }
    }

  • 相关阅读:
    ViewState EnableViewState 禁用与使用心得
    ashx获取处理数据的简单例子
    移动标签(marquee)属性详解
    SQL Server 2008 R2 企业版/开发版/标准版(中英文下载,带序列号)
    C#,Dictionary,asp.net 字典 用法及简单操作
    .net 后台提交表单,获取返回结果
    ASP.NET : 如何将服务端的多个文件打包下载
    puppet原理及配置
    linux开机启动详细流程
    SHELL日志分析 实例一
  • 原文地址:https://www.cnblogs.com/FLWL/p/5147986.html
Copyright © 2020-2023  润新知