protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) { ISite site = ParentInternal?.Site; if (IsHandleCreated && (site == null || !site.DesignMode)) { Rectangle oldBounds = Bounds; base.SetBoundsCore(x, y, width, height, specified); Rectangle newBounds = Bounds; int yDelta = oldBounds.Height - newBounds.Height; if (yDelta != 0) { // NOTE: This logic is to keep minimized MDI children anchored to // the bottom left of the client area, normally they are anchored // to the top right which just looks wierd! // NativeMethods.WINDOWPLACEMENT wp = new NativeMethods.WINDOWPLACEMENT { length = Marshal.SizeOf <NativeMethods.WINDOWPLACEMENT>() }; for (int i = 0; i < Controls.Count; i++) { Control ctl = Controls[i]; if (ctl != null && ctl is Form) { Form child = (Form)ctl; // Only adjust the window position for visible MDI Child windows to prevent // them from being re-displayed. if (child.CanRecreateHandle() && child.WindowState == FormWindowState.Minimized) { UnsafeNativeMethods.GetWindowPlacement(new HandleRef(child, child.Handle), ref wp); wp.ptMinPosition.Y -= yDelta; if (wp.ptMinPosition.Y == -1) { if (yDelta < 0) { wp.ptMinPosition.Y = 0; } else { wp.ptMinPosition.Y = -2; } } wp.flags = NativeMethods.WPF_SETMINPOSITION; UnsafeNativeMethods.SetWindowPlacement(new HandleRef(child, child.Handle), ref wp); wp.flags = 0; } } } } } else { base.SetBoundsCore(x, y, width, height, specified); } }
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) { ISite site = (this.ParentInternal == null) ? null : this.ParentInternal.Site; if (base.IsHandleCreated && ((site == null) || !site.DesignMode)) { Rectangle bounds = base.Bounds; base.SetBoundsCore(x, y, width, height, specified); Rectangle rectangle2 = base.Bounds; int num = bounds.Height - rectangle2.Height; if (num != 0) { System.Windows.Forms.NativeMethods.WINDOWPLACEMENT placement = new System.Windows.Forms.NativeMethods.WINDOWPLACEMENT { length = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.WINDOWPLACEMENT)) }; for (int i = 0; i < base.Controls.Count; i++) { Control control = base.Controls[i]; if ((control != null) && (control is Form)) { Form wrapper = (Form)control; if (wrapper.CanRecreateHandle() && (wrapper.WindowState == FormWindowState.Minimized)) { System.Windows.Forms.UnsafeNativeMethods.GetWindowPlacement(new HandleRef(wrapper, wrapper.Handle), ref placement); placement.ptMinPosition_y -= num; if (placement.ptMinPosition_y == -1) { if (num < 0) { placement.ptMinPosition_y = 0; } else { placement.ptMinPosition_y = -2; } } placement.flags = 1; System.Windows.Forms.UnsafeNativeMethods.SetWindowPlacement(new HandleRef(wrapper, wrapper.Handle), ref placement); placement.flags = 0; } } } } } else { base.SetBoundsCore(x, y, width, height, specified); } }