`
点击下图
  • 浏览: 31424 次
  • 性别: Icon_minigender_2
  • 来自: 武汉
社区版块
存档分类
最新评论

C#实现控件随窗体拖动而自动缩放其大小

 
阅读更多

C#代码:

  public  void AutoScale(Form frm)
        {
            frm.Tag = frm.Width.ToString() + "," + frm.Height.ToString();
            frm.SizeChanged += new EventHandler(frmScreen_SizeChanged);
        }

        private void frmScreen_SizeChanged(object sender, EventArgs e)
        {
            string[] tmp = ((Form)sender).Tag.ToString().Split(',');
            float width = (float)((Form)sender).Width / (float)Convert.ToInt16(tmp[0]);
            float heigth = (float)((Form)sender).Height / (float)Convert.ToInt16(tmp[1]) 代码生成器 ;

            ((Form)sender).Tag = ((Form)sender).Width.ToString() + "," + ((Form)sender).Height;

            foreach (Control control in ((Form)sender).Controls)
            {
                control.Scale(new SizeF(width, heigth));

            }
        }

       public frmScreen()
        {
            InitializeComponent();

                     AutoScale(this);
        }

 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics