【问题标题】:Double-click event on borderless forms无边框表单上的双击事件
【发布时间】:2019-04-11 02:54:03
【问题描述】:

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

[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】:

    尝试检查 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);
        }
      }
    }
    

    【讨论】:

    • 工作。非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-06
    • 1970-01-01
    • 2011-12-06
    • 1970-01-01
    • 2011-05-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多