我想控制子窗体在移动时不能超出MDI窗体的边框,如何实现呀

解决方案 »

  1.   

    是判断MDI的TOP和LEFT的值吗?有没有具体的代码
      

  2.   

            private void form1_Move(object sender, EventArgs e)
            {
                try
                {
                    Rectangle subRc = this.Bounds;
                    Rectangle parRc = this.Parent.Bounds;                if(!parRc.Contains(subRc))       //这句是关键
                    {
                        if (subRc.X < parRc.X)
                            this.Bounds.X = this.Parent.Bounds.X;                    if (subRc.Y < parRc.Y)
                            this.Bounds.Y = this.Parent.Bounds.Y;                    if (subRc.Right > parRc.Right)
                            this.Bounds.Right  = this.Parent.Bounds.Right ;                    if (subRc.Bottom > parRc.Bottom)
                            this.Bounds.Bottom = this.Parent.Bounds.Bottom;
                    }
                }
                catch(Exception ex)
                {            }        }