gpt4 book ai didi

c# - 鼠标双击仅在右键单击时触发

转载 作者:行者123 更新时间:2023-12-05 09:22:27 25 4
gpt4 key购买 nike

我想覆盖面板控件上的双击,所以我基本上是这样做的

HeaderPanel.MouseDoubleClick += (sender, args) =>
{
MaximizeOnClick(sender, args);
};

然而(奇怪的是)它只会在我双击鼠标右键时触发,而不会在正常双击左键时触发。 ?有什么问题?

更新 #1:我认为发生这种情况是因为我还覆盖了 MouseDown 事件,因为当我删除它时,左键单击有效,所以这两个事件之间是否存在某种交互或其他东西?

更新#2:

const int WM_NCLBUTTONDOWN = 0xA1;
const int HTCAPTION = 0x2;
const UInt32 WM_NCHITTEST = 0x0084;
const UInt32 WM_MOUSEMOVE = 0x0200;
const UInt32 HTLEFT = 10;
const UInt32 HTRIGHT = 11;
const UInt32 HTBOTTOMRIGHT = 17;
const UInt32 HTBOTTOM = 15;
const UInt32 HTBOTTOMLEFT = 16;
const UInt32 HTTOP = 12;
const UInt32 HTTOPLEFT = 13;
const UInt32 HTTOPRIGHT = 14;
const int RESIZE_HANDLE_SIZE = 10;

[DllImport("User32.dll")]
public static extern bool ReleaseCapture();

[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);

protected override void WndProc(ref Message m)
{
bool handled = false;
if (m.Msg == WM_NCHITTEST || m.Msg == WM_MOUSEMOVE)
{
Size formSize = Size;
Point screenPoint = new Point(m.LParam.ToInt32());
Point clientPoint = PointToClient(screenPoint);

Dictionary<UInt32, Rectangle> boxes = new Dictionary<UInt32, Rectangle>
{
{HTBOTTOMLEFT, new Rectangle(0, formSize.Height - RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE)},
{HTBOTTOM, new Rectangle(RESIZE_HANDLE_SIZE, formSize.Height - RESIZE_HANDLE_SIZE, formSize.Width - 2*RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE)},
{HTBOTTOMRIGHT, new Rectangle(formSize.Width - RESIZE_HANDLE_SIZE, formSize.Height - RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE)},
{HTRIGHT, new Rectangle(formSize.Width - RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE, formSize.Height - 2*RESIZE_HANDLE_SIZE)},
{HTTOPRIGHT, new Rectangle(formSize.Width - RESIZE_HANDLE_SIZE, 0, RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE)},
{HTTOP, new Rectangle(RESIZE_HANDLE_SIZE, 0, formSize.Width - 2*RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE)},
{HTTOPLEFT, new Rectangle(0, 0, RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE)},
{HTLEFT, new Rectangle(0, RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE, formSize.Height - 2*RESIZE_HANDLE_SIZE)}
};

foreach (KeyValuePair<UInt32, Rectangle> hitBox in boxes)
{
if (hitBox.Value.Contains(clientPoint))
{
m.Result = (IntPtr)hitBox.Key;
handled = true;
break;
}
}
}

if (!handled)
base.WndProc(ref m);
}

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

private void MaximizeOnClick(object sender, EventArgs eventArgs)
{
if (FormWindowState.Normal == WindowState)
{
MaximumSize = Screen.PrimaryScreen.WorkingArea.Size;
WindowState = FormWindowState.Maximized;
}
else
{
MaximumSize = new Size(0, 0);
WindowState = FormWindowState.Normal;
}
Panel.Select();
}

最佳答案

好的,我已经通过处理鼠标按下前的双击事件解决了这个问题...基本上改变了这个

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

对此

private void HeaderPanelOnMouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && e.Clicks >= 2) {
MaximizeOnClick(sender, e);
return;
}

if (e.Button != MouseButtons.Left) {
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
}

关于c# - 鼠标双击仅在右键单击时触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26197728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com