1
在我的項目中,我使用WS_EX_TRANSPARENT標誌動態定義半透明窗體是否應接收用戶鼠標事件。啓用/禁用GUI控件將禁用我的OnMouseWheel覆蓋
爲了使它更直觀,我添加了代碼來禁用啓用WS_EX_TRANSPARENT時的所有可見控件,但是,當調用此代碼時,它似乎'鎖定'我的OnMouseWheel
覆蓋。
以下是我的代碼。我應該指出,如果我註釋掉'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;
}
這就是它,完美工作;非常感謝! – sebf 2011-05-30 11:36:27