繁体   English   中英

无边框表单上的双击事件

[英]Double-click event on borderless forms

我创建了一个无边框表单,并且已经能够通过以下代码激活表单移动事件:

[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();

private void FASTMain_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        ReleaseCapture();
        SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
    }
}

private void FASTMain_Move(object sender, EventArgs e)
{
    WindowState = FormWindowState.Normal;
}

我想知道是否也可以拦截表单上的鼠标双击事件。

尝试检查 e.Clicks 值:

protected override void OnMouseDown(MouseEventArgs e) {
  base.OnMouseDown(e);

  if (e.Button == MouseButtons.Left) {
    if (e.Clicks > 1) {
      // do something with double-click
    } else {
      ReleaseCapture();
      SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
    }
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM