在无边框表单上双击事件

问题描述 投票:1回答:1

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

[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;
}

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

c# winforms double-click borderless
1个回答
1
投票

尝试检查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);
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.