protected override void OnNonClientMouseDown(NonClientMouseEventArgs args)
        {
            if (args.Button != MouseButtons.Left)
            {
                return;
            }

            switch (args.HitTest)
            {
            case (int)NativeMethods.NCHITTEST.HTCLOSE:
            {
                //NativeMethods.POINT pt = NativeMethods.POINT.FromPoint(args.Location);
                if (DepressButton(closeButton))
                {
                    NativeMethods.SendMessage(this.Handle,
                                              (int)NativeMethods.WindowMessages.WM_SYSCOMMAND,
                                              (IntPtr)NativeMethods.SystemCommands.SC_CLOSE, IntPtr.Zero);
                }
                args.Handled = true;
                break;
            }

            case (int)NativeMethods.NCHITTEST.HTMINBUTTON:
            {
                //		NativeMethods.POINT pt = NativeMethods.POINT.FromPoint(args.Location);
                if (DepressButton(minimizeButton))
                {
                    NativeMethods.SendMessage(this.Handle,
                                              (int)NativeMethods.WindowMessages.WM_SYSCOMMAND,
                                              (IntPtr)NativeMethods.SystemCommands.SC_MINIMIZE, IntPtr.Zero);
                }
                args.Handled = true;
                break;
            }

            case (int)NativeMethods.NCHITTEST.HTMAXBUTTON:
            {
                if (DepressButton(maximizeButton))
                {
                    int sc = (WindowState == FormWindowState.Maximized)?
                             (int)NativeMethods.SystemCommands.SC_RESTORE : (int)NativeMethods.SystemCommands.SC_MAXIMIZE;

                    NativeMethods.SendMessage(this.Handle,
                                              (int)NativeMethods.WindowMessages.WM_SYSCOMMAND,
                                              (IntPtr)sc, IntPtr.Zero);
                }
                args.Handled = true;
                break;
            }
            }

            //TODO: handle other buttons if exist
        }
Ejemplo n.º 2
0
        private void WmNCLButtonDown(ref Message msg)
        {
            Point pt = this.PointToWindow(new Point(msg.LParam.ToInt32()));
            NonClientMouseEventArgs args = new NonClientMouseEventArgs(
                MouseButtons.Left, 1, pt.X, pt.Y, 0, msg.WParam.ToInt32());

            OnNonClientMouseDown(args);
            if (!args.Handled)
            {
                DefWndProc(ref msg);
            }
            msg.Result = NativeMethods.TRUE;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Called each time one of the mouse buttons was pressed over the non-client area.
 /// </summary>
 /// <param name="args">NonClientMouseEventArgs contain mouse position, button pressed,
 /// and hit-test code for current position. </param>
 protected virtual void OnNonClientMouseDown(NonClientMouseEventArgs args)
 {
 }
 private void WmNCLButtonDown(ref Message msg)
 {
     Point pt = this.PointToWindow(new Point(msg.LParam.ToInt32()));
     NonClientMouseEventArgs args = new NonClientMouseEventArgs(
         MouseButtons.Left, 1, pt.X, pt.Y, 0, msg.WParam.ToInt32());
     OnNonClientMouseDown(args);
     if (!args.Handled)
     {
         DefWndProc(ref msg);
     }
     msg.Result = NativeMethods.TRUE;
 }
 /// <summary>
 /// Called each time one of the mouse buttons was pressed over the non-client area.
 /// </summary>
 /// <param name="args">NonClientMouseEventArgs contain mouse position, button pressed,
 /// and hit-test code for current position. </param>
 protected virtual void OnNonClientMouseDown(NonClientMouseEventArgs args)
 {
 }