zoukankan      html  css  js  c++  java
  • C#控件随窗体大小自动调整

    构造函数中:

                int count = this.Controls.Count * 2 + 2;
                float [] factor=new float [count];
                int i = 0;
                factor[i++] = Size.Width;
                factor[i++] = Size.Height;
                foreach (Control ctrl in this.Controls)
                {
                    factor[i++] = ctrl.Location.X / (float)Size.Width;
                    factor[i++] = ctrl.Location.Y / (float)Size.Height;
                    ctrl.Tag = ctrl.Size;
                }
                Tag = factor;

    为控件的TAG属性加入大小

    Resize事件中自动调整大小

            private void Summary_Resize(object sender, EventArgs e)
            {
                float[] scale = (float[])Tag;
                int i = 2;
                foreach (Control ctrl in this.Controls)
                {
                    ctrl.Left = (int)(Size.Width * scale[i++]);
                    ctrl.Top = (int)(Size.Height * scale[i++]);
                    ctrl.Width = (int)(Size.Width / (float)scale[0] * ((Size)ctrl.Tag).Width);
                    ctrl.Height = (int)(Size.Height / (float)scale[1] * ((Size)ctrl.Tag).Height);

                }
            }

  • 相关阅读:
    Node项目
    Angular模块/服务/MVVM
    Angular介绍1
    Node环境配置及Gulp工具
    Linux及Git介绍
    数据库MySQL
    ReactiveCocoa 监听枚举类型enumerate 或者 NSInteger类型
    ReactiveCocoa 监听布尔(BOOL)类型改变
    python3.7 urlopen请求HTTPS警告'CERTIFICATE_VERIFY_FAILED'解决办法
    Centos yum命令
  • 原文地址:https://www.cnblogs.com/qzbnet/p/1415530.html
Copyright © 2011-2022 走看看