以透明形式点击进入桌面
我有一个屏幕捕获实用程序,可以用橡皮筋在桌面上的某个区域进行操作。我已经以相当简单的方式做到了这一点,我有一个与屏幕大小相同的表单,我在其上绘制了转换为灰度的桌面屏幕截图。当用户按住鼠标左键时,他/她可以选择表单上的区域。用户绘制的矩形用透明颜色填充。一旦用户抬起鼠标,透明矩形就会保留在原处,并且实际的桌面可见。我的问题来了: 在我的开发 PC 上,我实际上可以单击这个透明矩形并进行导航等。而在我的另一台 PC 上,表单会通过鼠标单击实际的透明矩形进行响应。
我在 C# 中使用 .NET 4.0,关于如何让它在所有情况下实际点击到桌面有什么想法吗?
谢谢你,非常感谢:)
I have a screen capturing utility on which I can rubber band an area on the desktop. I've done this is a fairly easy manner, I have a form which is the same size as the screen on which I draw a screenshot of the desktop transformed into grayscale. When the user holds down the left mouse button he/she can select an area on the form. The rectangle which the user draws is filled with TransparentColor. Once the users lifts up his/her mouse the transparent rectangle is left in place and the actual desktop is visible. Here comes my problem:
On my dev PC I can actually click through this transparent rectangle and navigate around etc. while on my other PC the form responds on mouse clicks on the actual transparent rectangle.
I'm using .NET 4.0 in C#, any ideas on how I can make it actually click through to the desktop on all cases??
Thank you and much appreciated :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过深入研究后,我设法找到了解决此问题的正确解决方案。事实证明,通过正确的 Win32 API 调用,可以将表单设置为“不可见”以进行鼠标单击。这可以通过以下方式实现:
但万事皆有窍门。您需要注意的是,在论坛上进行的所有点击都将通过表单并发送到表单下方的任何内容。为了确保如果我单击表单(例如按钮)并且我希望单击该按钮,我做了一个简单的技巧。我在后台有一个计时器,每 N 毫秒运行一次并分析光标的位置。如果它位于我想要的区域之上,它将通过 SetFormNormal() 将表单设置为正常,否则它将是透明的。
希望这段代码有帮助并且人们会使用它。
I managed to find a proper solution for this problem after looking very deeply into this. It turns out with the proper Win32 API calls it is possible to set a form "Invisible" to mouse clicks. This can be achieved by:
But there is a trick to everything. You need to be careful that all clicks made on the forum will fall through the form and be sent to anything below the form. To ensure that if I click on my form e.g. on a button and I want the button clicked I did a simple trick. I have a timer in the background running every N milliseconds and analyzing the position of the Cursor. If it's above the area I want it to be, it'll set the Form to Normal via SetFormNormal() otherwise it'll be transparent.
Hope this code bit helps and people will use it.