• winform 窗体大小变化时,如何设置使控件一起按照比例变大


     public Form()
            {
                InitializeComponent();
                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;
            }
    private void Form_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); 
            }
        }

    摘自http://bbs.csdn.net/topics/350169743   laj0600310219。

    本博客文章皆出于学习目的,个人总结或摘抄整理自网络。引用参考部分在文章中都有原文链接,如疏忽未给出请联系本人。另外,作为一名菜鸟程序媛,如文章内容有错误,欢迎点击博客右上方的扣扣链接指导交流。
  • 相关阅读:
    Vue3源码系列之触发更新的实现
    Vue3源码系列之依赖收集的实现
    Vue3源码系列之reactiveApi实现
    删除链表的倒数第n个节点
    Shared_ptr 参考实现
    linux 目录结构 比较老
    C++11 bind function
    状态机DP
    尾递归
    秒杀系统的构建(2)
  • 原文地址:https://www.cnblogs.com/goingforward/p/5048669.html
Copyright © 2020-2023  润新知