日期:2014-05-20  浏览次数:21093 次

如何使子窗体的大小随父窗体变化而变化
如题

------解决方案--------------------
在FORM的RESIZE事件中控制子窗体
------解决方案--------------------
事先确定好各个子窗体与父窗体的比例,在父窗体的Resize事件中根据父窗体的大小计算并设置各个子窗体的位置和大小。
------解决方案--------------------
可以在父窗体的Resize事件中控制子窗体的Top,Left,Width,Height等属性
------解决方案--------------------
http://topic.csdn.net/u/20090817/00/01bba0c6-eafb-4b88-bbbf-789ac5b9beb6.html
------解决方案--------------------
C# code

 bool isno = false;//控制是否第一次改变。因为第一次打开主窗体里就会执行Resize事件
        int IntoHeight, IntoWidth;//放入每次改变时的父窗体值
        float TempHeight, TempWidth;//获得每次放大放小的比例值

        private void main_Load(object sender, EventArgs e)
        {
            isno = true;
            IntoHeight = this.Height; IntoWidth = this.Width;
        }

        private void main_Resize(object sender, EventArgs e)
        {
            if (isno)
            {
                TempHeight = float.Parse(this.Height.ToString()) / float.Parse(this.IntoHeight.ToString());
                TempWidth = float.Parse(this.Width.ToString()) / float.Parse(this.IntoWidth.ToString());
                IntoHeight = this.Height; IntoWidth = this.Width;
                ChangAllChildRenSize();
            }
        }

        public void ChangAllChildRenSize()
        {
            foreach (Form tempChildForm in this.MdiChildren)
            {
                tempChildForm.Height = int.Parse(Convert.ToString(Math.Round(tempChildForm.Height * TempHeight,0)));
                tempChildForm.Width = int.Parse(Convert.ToString(Math.Round(tempChildForm.Width * TempWidth,0)));
            }
        }

------解决方案--------------------
探讨
C# codebool isno=false;//控制是否第一次改变。因为第一次打开主窗体里就会执行Resize事件int IntoHeight, IntoWidth;//放入每次改变时的父窗体值float TempHeight, TempWidth;//获得每次放大放小的比例值privatevoid main_Load(object sender, EventArgs e)
{
¡­

------解决方案--------------------
C# code


  private void test_Click(object sender, EventArgs e)
        {
            //MessageBox.Show(((float)52 / (float)45).ToString() + "qq");
            Form2 subform = new Form2();
            subform.MdiParent = this;
            subform.Show();
            if (this.WindowState == FormWindowState.Normal)
            {
                foreach (Form obj in this.MdiChildren)//obj.Width / obj.Height I will know it soon. 
                {
                     changeW = (double)this.Width / (double)obj.Width;
                     changeH = (double)this.Height / (double)obj.Height;
                }
            }
            
        }

        private void Form1_SizeChanged(object sender, EventArgs e)
        {
            Form2 subform = new Form2();//
            if (this.WindowState == FormWindowState.Maximized)
            {
                foreach (Form obj in this.MdiChildren)
                {
                    obj.WindowState = FormWindowState.Maximized;

                    obj.Show();
                }
            }
            if (this.WindowState == FormWindowState.Normal)
            {
                foreach (Form obj in this.MdiChildren)//obj.Width / obj.Height
                {
                   
                    double a = (double)this.Width / changeW;
                    if (a.ToString() != string.Empty)
                    {
                        obj.Width = int.Parse(Convert.ToString(Math.Round(a,0)));
                    }

                    double b = (double)this.Height / changeH;
                    if (b.ToString() != string.Empty)
                    {
                        obj.Height = int.Parse(Convert.ToString(Math.Round(b, 0)));//float转换为int型时,“.”不能转换要注意
                    }
                }
            }
             
           
        }