点击事件未在扩展玻璃区域中引发?
所以我只是使用 DwmExtendFrameIntoClientArea (Vista / 7 Aero 的东西)将窗体的玻璃区域扩展到客户区域。
我已经在覆盖 Form 类方法 OnMouseDown() 中发送了一条 Windows 消息,导致窗口可以随玻璃区域移动,如此处所述 使无边框表单可移动?。
但是,因此,当单击扩展玻璃区域时,我没有收到任何形式的 Click / MouseClick / DoubleClick 等事件。
实际上,我希望当我双击顶部扩展玻璃区域时,表单最大化,就像普通标题栏一样。
下面是 Form 继承类的代码:
protected override void OnMouseDown(MouseEventArgs e)
{
// Fensterverschiebung in Glass-Regionen
if (_glassMovable && e.Button == MouseButtons.Left
&& (e.X < _glassPadding.Left || e.X > Width - _glassPadding.Right
|| e.Y < _glassPadding.Top || e.Y > Height - _glassPadding.Bottom))
{
NativeMethods.ReleaseCapture();
NativeMethods.SendMessage(Handle, NativeMethods.WM_NCLBUTTONDOWN,
NativeMethods.HT_CAPTION, 0);
}
base.OnMouseDown(e);
}
protected override void OnMouseDoubleClick(MouseEventArgs e)
{
// Fenstermaximierung / Minimierung in Glass-Regionen
if (MaximizeBox && e.Button == MouseButtons.Left && e.Y < _glassPadding.Top)
{
if (WindowState == FormWindowState.Normal)
{
WindowState = FormWindowState.Maximized;
}
else if (WindowState == FormWindowState.Maximized)
{
WindowState = FormWindowState.Normal;
}
}
base.OnMouseDoubleClick(e);
}
有什么方法可以让它工作吗?
so I just expanded the glass area of my form into the client area with DwmExtendFrameIntoClientArea (Vista / 7 Aero stuff).
I have already sent a Windows message in the override Form class method OnMouseDown() causing the window to be movable with the glass area, as explained here Make a borderless form movable?.
However because of this, I am not receiving any form Click / MouseClick / DoubleClick etc. events when clicking on the expanded glass area.
I actually want the form to maximize when I double click the top expanded glass area, like normal titlebars do.
Here's the code of the Form-inheriting class:
protected override void OnMouseDown(MouseEventArgs e)
{
// Fensterverschiebung in Glass-Regionen
if (_glassMovable && e.Button == MouseButtons.Left
&& (e.X < _glassPadding.Left || e.X > Width - _glassPadding.Right
|| e.Y < _glassPadding.Top || e.Y > Height - _glassPadding.Bottom))
{
NativeMethods.ReleaseCapture();
NativeMethods.SendMessage(Handle, NativeMethods.WM_NCLBUTTONDOWN,
NativeMethods.HT_CAPTION, 0);
}
base.OnMouseDown(e);
}
protected override void OnMouseDoubleClick(MouseEventArgs e)
{
// Fenstermaximierung / Minimierung in Glass-Regionen
if (MaximizeBox && e.Button == MouseButtons.Left && e.Y < _glassPadding.Top)
{
if (WindowState == FormWindowState.Normal)
{
WindowState = FormWindowState.Maximized;
}
else if (WindowState == FormWindowState.Maximized)
{
WindowState = FormWindowState.Normal;
}
}
base.OnMouseDoubleClick(e);
}
Is there any way to get this to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

BoltClocks 链接到 WPF 解决方案启发了我编写以下类似的 WinForms 代码。
我现在重写 WndProc 而不是 OnMouse* 事件。
玻璃区域的行为与标题栏完全相同,例如,Windows 7 中支持 Dock 的拖放,然后双击以最大化/恢复。此外,该解决方案现在支持右键单击玻璃区域时的系统窗口上下文菜单。
BoltClocks link to a solution for WPF inspired me for the following, similar code for WinForms.
I now override WndProc instead of the OnMouse* events.
The glass region behaves exactly like a title bar, e.g. drag'n'drop with dock support in Windows 7 and double click for maximizing / restoring. Additionally, this solution now supports the system window context menu when right clicking the glass area.