Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        /// <include file='doc\MDIClient.uex' path='docs/doc[@for="MdiClient.SetBoundsCore"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
        {
            ISite site = (ParentInternal == null) ? null : 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;

                // 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();
                wp.length = Marshal.SizeOf(typeof(NativeMethods.WINDOWPLACEMENT));

                for (int i = 0; i < Controls.Count; i++)
                {
                    Control ctl = Controls[i];
                    if (ctl != null && ctl is Form)
                    {
                        Form child = (Form)ctl;
                        if (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);
            }
        }