Nathan Nathan - 3 months ago 9
C# Question

Clicking Through a Form?

So I have this code:

private void PanelsFade()
{
var _initialStyle = GetWindowLong(Handle, -20);
SetWindowLong(this.Handle, -20, _initialStyle | 0x80000 | 0x20);
if (Opacity == 1) {
Opacity = 0.5;
}
}

private void PanelsShow()
{
var _initialStyle = GetWindowLong(Handle, -20);
SetWindowLong(this.Handle, -20, _initialStyle | ~(0x80000 | 0x20));
if (Opacity == 0.5) {
Opacity = 1;
}
}


When I fade the panels I can click through them as supposed, but when I restore the panels (PanelsShow()) I can still click through them (unable to click buttons, etc)...

Answer

I tested you code, and what you are doing is not a correct way of removing a bitwise combined number.

This:

_initialStyle | ~(0x80000 | 0x20)

should be this:

_initialStyle & ~(0x80000 | 0x20)
Comments