Exemple #1
0
        protected override void  WndProc(ref Message m)
        {
            if ((m.Msg == NativeMethods.WM_NCHITTEST) && SizingGrip)
            {
                // if we're within the grip bounds tell windows
                // that we're the bottom right of the window.
                Rectangle sizeGripBounds = SizeGripBounds;
                int       x = NativeMethods.Util.LOWORD(m.LParam);
                int       y = NativeMethods.Util.HIWORD(m.LParam);


                if (sizeGripBounds.Contains(PointToClient(new Point(x, y))))
                {
                    HandleRef rootHwnd = WindowsFormsUtils.GetRootHWnd(this);

                    // if the main window isnt maximized - we should paint a resize grip.
                    // double check that we're at the bottom right hand corner of the window.
                    if (rootHwnd.Handle != IntPtr.Zero && !UnsafeNativeMethods.IsZoomed(rootHwnd))
                    {
                        // get the client area of the topmost window.  If we're next to the edge then
                        // the sizing grip is valid.
                        NativeMethods.RECT rootHwndClientArea = new NativeMethods.RECT();
                        UnsafeNativeMethods.GetClientRect(rootHwnd, ref rootHwndClientArea);

                        // map the size grip FROM statusStrip coords TO the toplevel window coords.
                        NativeMethods.POINT gripLocation;
                        if (RightToLeft == RightToLeft.Yes)
                        {
                            gripLocation = new NativeMethods.POINT(SizeGripBounds.Left, SizeGripBounds.Bottom);
                        }
                        else
                        {
                            gripLocation = new NativeMethods.POINT(SizeGripBounds.Right, SizeGripBounds.Bottom);
                        }
                        UnsafeNativeMethods.MapWindowPoints(new HandleRef(this, this.Handle), rootHwnd, gripLocation, 1);

                        int deltaBottomEdge = Math.Abs(rootHwndClientArea.bottom - gripLocation.y);
                        int deltaRightEdge  = Math.Abs(rootHwndClientArea.right - gripLocation.x);

                        if (RightToLeft != RightToLeft.Yes)
                        {
                            if ((deltaRightEdge + deltaBottomEdge) < 2)
                            {
                                m.Result = (IntPtr)NativeMethods.HTBOTTOMRIGHT;
                                return;
                            }
                        }
                    }
                }
            }
            base.WndProc(ref m);
        }