.NET 中的非透明点击表单
在.NET中,是否可以创建一个可以点击的非透明表单?我认为应该有某种 API 可以将鼠标点击传输到表单后面的窗口。哪一个?
In .NET, is it possible to create a non-transparent form which can be clicked through? I assume there should be some sort of API to transfer mouse clicks to windows right behind the form. Which one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要进行表单点击,您需要从 Windows API 中 P/Invoke 一些函数并设置表单的 扩展窗口样式。我任意选择用 VB.NET 来表示示例代码。如果这不是您的偏好,可以轻松将其转换为 C#。
从
GetWindowLong
函数 开始,您可以使用该函数将用于检索扩展窗口样式。您还需要它的姊妹函数
SetWindowLong
,指定附加的扩展窗口样式。以及需要设置的扩展窗口样式的常量:
现在要使用所有这些,您可以覆盖表单的
OnLoad
方法 并添加以下行:当然,请注意,用户现在不可能与表单上的元素进行交互,并且极 > 他们很难关闭它。仔细考虑这是否真的是您想要做的。
To make a form click-through, you'll need to P/Invoke a few functions from the Windows API and set the form's extended window styles. I've arbitrarily chosen to represent the sample code in VB.NET. If that's not your preference, it's easily converted to C#.
Start with the
GetWindowLong
function, which you will use to retrieve the extended window styles.You'll also need its sister function,
SetWindowLong
, to specify the additional extended window styles.And the constant for the extended window style that will need to be set:
And now to use all of this, you can override your form's
OnLoad
method and add the following lines:Of course, note that it's now going to be impossible for the user to interact with elements on your form and extremely difficult for them to close it. Consider carefully whether this is really what you want to do.