Winform窗口最大化时里面的控件布局如何做到最佳等比例缩放

请不要回答用Anchor设置,我尝试过下面的方法!/*******************设定程序中可能要用到的用以存储初始数据的动态数组及相关私有变量*********... 请不要回答用Anchor设置,我尝试过下面的方法!
/*******************设定程序中可能要用到的用以存储初始数据的动态数组及相关私有变量********************/
private ArrayList InitialCrl = new ArrayList();//用以存储窗体中所有的控件名称

private ArrayList CrlLocationX = new ArrayList();//用以存储窗体中所有的控件原始位置
private ArrayList CrlLocationY = new ArrayList();//用以存储窗体中所有的控件原始位置
private ArrayList CrlSizeWidth = new ArrayList();//用以存储窗体中所有的控件原始的水平尺寸
private ArrayList CrlSizeHeight = new ArrayList();//用以存储窗体中所有的控件原始的垂直尺寸
private int FormSizeWidth;//用以存储窗体原始的水平尺寸
private int FormSizeHeight;//用以存储窗体原始的垂直尺寸
private double FormSizeChangedX;//用以存储相关父窗体/容器的水平变化量
private double FormSizeChangedY;//用以存储相关父窗体/容器的垂直变化量
private int Wcounter = 0;//为防止递归遍历控件时产生混乱,故专门设定一个全局计数器
/****************************************************************************************************************/
public void GetAllCrlLocation(Control CrlContainer)//获得并存储窗体中各控件的初始位置
{
foreach (Control iCrl in CrlContainer.Controls)
{
if (iCrl.Controls.Count > 0)
GetAllCrlLocation(iCrl);
InitialCrl.Add(iCrl);
CrlLocationX.Add(iCrl.Location.X);
CrlLocationY.Add(iCrl.Location.Y);
}
}
使用上面代码时,最大化时,有时候(控件集合内子空间太多)出现界面控件只显示一部分或者控件消失了!
展开
 我来答
ghzx071458
2015-05-08 · TA获得超过1416个赞
知道小有建树答主
回答量:651
采纳率:50%
帮助的人:384万
展开全部
            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 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 Form1_Resize(object sender, EventArgs e)
        {
            // throw new Exception("The method or operation is not implemented.");  
            float newx = (this.Width) / X;
            //  float newy = (this.Height - this.statusStrip1.Height) / (Y - y);  
            float newy = this.Height / Y;
            setControls(newx, newy, this);
            //this.Text = this.Width.ToString() + " " + this.Height.ToString();  
        }

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

            X = this.Width;
            Y = this.Height;
         //   y = this.statusStrip1.Height;
            setTag(this);  

        }
        忘了加Private float X ,Y;
光点科技
2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件... 点击进入详情页
本回答由光点科技提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式