如何解决启用/禁用GUI控件将禁用我的OnMouseWheel覆盖
|| 在我的项目中,我使用WS_EX_TRANSPARENT标志动态定义半透明表单是否应该接收用户的鼠标事件。 为了使其更直观,我添加了代码,以在启用WS_EX_TRANSPARENT时禁用所有可见控件,但是,当调用此代码时,它似乎“锁定”了我的“ 0”替代。 下面是我的代码。我应该指出,如果我注释掉\'EnableGUIControls \'方法,则此代码可以正常工作-实际上,如果注释掉\'EnableGUIControls \'方法中的任何行,它都可以正常工作-因此,这与禁用所有功能有关控件。 从窗体中移出焦点并重新激活它可以解决此问题,但是手动调用Form.Activte()却不能。 我正在考虑禁用所有可见控件的方式以某种方式禁用父级?有人知道发生了什么吗? private void SetTransparentToMouse(bool should_be_transparent)
{
IntPtr flags = GetWindowLong(this.Handle,GWL_EXSTYLE);
if (((flags.ToInt64() & WS_EX_TRANSPARENT.ToInt64()) > 0) == should_be_transparent)
{
return;
}
else
{
SwapTransparent();
EnableGUIControls(!should_be_transparent);
}
}
private void SwapTransparent()
{
IntPtr flags = new IntPtr(GetWindowLong(this.Handle,GWL_EXSTYLE).ToInt64() ^ WS_EX_TRANSPARENT.ToInt64());
SetWindowLong(this.Handle,GWL_EXSTYLE,flags);
}
protected override void OnKeyUp(KeyEventArgs e)
{
if (!e.Alt)
{
SetTransparentToMouse(default_mouse_transparency);
}
base.OnKeyUp(e);
}
protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
{
if (e.Alt)
{
SetTransparentToMouse(!default_mouse_transparency);
}
base.OnKeyDown(e);
}
//Commenting out the call to this,or any line within this resolves the problem!:
void EnableGUIControls(bool enabled)
{
this.Button_Opacity.Enabled = enabled;
this.Button_Close.Enabled = enabled;
this.Button_Minimize.Enabled = enabled;
this.Button_Open.Enabled = enabled;
this.Button_Pan.Enabled = enabled;
this.Button_Sizemode.Enabled = enabled;
this.Button_Zoom.Enabled = enabled;
}
解决方法
当所有控件都被禁用时,没有集中的控件可以捕获并将鼠标消息重定向到窗体。尝试使用Form.Focus()而不是Form.Activate()。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。