Exemplo n.º 1
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;
        }
Exemplo n.º 2
0
        protected override void OnNonClientMouseDown(NonClientMouseEventArgs args)
        {
            if (args.Button != MouseButtons.Left)
            {
                return;
            }

            // custom button
            foreach (CaptionButton button in this.CaptionButtons)
            {
                if (args.HitTest > short.MaxValue && args.HitTest == button.HitTestCode && button.Visible && button.Enabled)
                {
                    ((CustomCaptionButton)button).OnClick();
                    args.Handled = true;
                    return;
                }
            }

            // find appropriate button
            foreach (CaptionButton button in this.CaptionButtons)
            {
                // [1530]: Don't execute any action when button is disabled or not visible.
                if (args.HitTest == button.HitTestCode && button.Visible && button.Enabled)
                {
                    Log(MethodInfo.GetCurrentMethod(), "MouseDown: button = {0}", button);

                    if (DepressButton(button))
                    {
                        if (button.SystemCommand >= 0)
                        {
                            int sc = button.SystemCommand;

                            if (button == _maximizeButton)
                            {
                                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);
                        }

                        //TODO: fire event for custom button

                        args.Handled = true;
                    }
                    return;
                }
            }
        }
Exemplo 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)
 {
 }