C#形式的点击 [英] Click-through in C# Form
问题描述
我创建了一个半透明的表单。我希望人们能够点击表单区域,而表单无法处理点击。我希望表单下方的任何内容都可以接收click事件。
I've created a semi-transparent form. I'd like for people to be able to click on the form area, and for form not handle the click. I'd like whatever is underneath the form to receive the click event instead.
推荐答案
您可以使用 SetWindowLong
:
int initialStyle = GetWindowLong(this.Handle, -20);
SetWindowLong(this.Handle, -20, initialStyle | 0x80000 | 0x20);
这里有一些魔术数字:
-
-20
– GWL_EXSTYLE
检索扩展的窗口样式。
Retrieves the extended window styles.
0x80000
– WS_EX_LAYERED
创建一个分层窗口。
0x20
– WS_EX_TRANSPARENT
指定在该窗口下方的兄弟姐妹(由同一线程创建)具有b之前,不应绘制以此样式创建的窗口een画。该窗口显示为透明,因为基础同级窗口的位已被绘制。
Specifies that a window created with this style should not be painted until siblings beneath the window (that were created by the same thread) have been painted. The window appears transparent because the bits of underlying sibling windows have already been painted.
网络上有很多有关如何执行此操作的文章,例如此。
There are numerous articles all over the web on how to do this, such as this one.
这篇关于C#形式的点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!