无边框窗体的双击事件
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);
}
}
}
我创建了一个无边框表单,并且我已经能够通过以下代码激活表单移动事件:
[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);
}
}
}