//1.设置父窗体(主窗体)的AutoScrollMinSize大于父窗体的Size //例如主窗体(400,400), AutoScrollMinSize(500,500) //2.设置主窗体的IsMdiContainer为true private void Form2_Load(object sender, EventArgs e) { //悬浮窗体 Form3 f3 = new Form3(); //制定悬浮Mid子窗体的父窗体是该主窗体 f3.MdiParent = this; //事件委托 f3.LocationChanged += new EventHandler(frm_LocationChanged); f3.Show(); } //窗体位置改变事件 private void frm_LocationChanged(object sender, EventArgs e) { Form frm = (Form)sender; if (frm.Location.X + frm.Width > this.Width) { //15:悬浮窗体左右边界的宽度,根据实际情况微调 frm.Left = this.Width - frm.Width - 15; } if (frm.Location.X < 0) { frm.Left = 0; } if (frm.Location.Y < 0) { frm.Top = 0; } if (frm.Location.Y + frm.Height > this.Height) { //40:悬浮窗体上下边界的高度,根据实际情况微调 frm.Top = this.Height - frm.Height - 40; } }