예제 #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;
		}
예제 #2
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)
		{
			if (args.Button != MouseButtons.Left)
				return;

			// custom button
			foreach (CustomCaptionButton 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 (CustomCaptionButton 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);
						}
						else if (button == _settingsButton)
						{
							if (SettingsClick != null)
								SettingsClick(button, new EventArgs());
						}
						else if (button == _aboutButton)
						{
							if (AboutClick != null)
								AboutClick(button, new EventArgs());
						}
						args.Handled = true;
					}
					return;
				}
			}
		}