Windows 窗体 C# 中的 TransparencyKey 问题

发布于 2024-11-04 18:28:45 字数 275 浏览 1 评论 0原文

我试图在.NET 2.0 中拥有一个透明的表单,该表单位于顶部,鼠标单击时不可见,但可以在其上绘图。通过将 TransparencyKey 设置为表单的背景颜色,我可以轻松实现此目的。但在所有 java 程序(例如 JDownloader、Vuze、Open Office)中,有一个非常容易重现的问题:有时,当显示上下文菜单时,在我单击其他位置后,部分(或整个)菜单仍然可见。它在物理上是关闭的,因为它无法单击任何项​​目,但它的图像保留在我顶部的隐形窗体上 - 可能在重绘时出现了一些问题。我非常感谢任何帮助。

雨果

I'm trying to have in .NET 2.0 a transparent form, that is on top, invisible for mouse clicks but is possible to draw on it. I can easily reach this by setting the TransparencyKey to background color of the form. But there is one very easy to reproduce problem in all java programs (e.g. JDownloader, Vuze, Open Office): sometime when context menu is shown it leaves the part of (or whole) menu still visible after I click somewhere else. It is physically closed because it is unable to click on any item, but the image of it stays on my top invisible form - probably there was some problem in redrawing. I be very grateful for any help.

Hugo

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

筱武穆 2024-11-11 18:28:45

普通的 Windows 应用程序将上下文菜单实现为真实的窗口,因此当用户关闭它们时,下面的所有窗口都会正确接收通知并重新绘制自己,因此菜单的图像不会“留在”任何地方。

您遇到问题的 Java 应用程序很可能通过直接在屏幕上绘制来实现上下文菜单,并且当菜单被关闭时,应用程序会自行滚动并使其下方的所有窗口无效。我猜测此方法不会使您的应用程序占用的区域无效,因为它认为您的窗口位于其上方并且没有意识到您的应用程序是透明的(这是猜测 - 我不确定。如果这些应用程序的上下文菜单看起来与本机应用程序的菜单不同,那么这可能就是发生的情况)。

如果发生这种情况,您无能为力。您可以做的一件事是自己绘制到屏幕上,而不是使用透明窗口。或者您可以在表单上设置一个计时器,定期调用刷新/无效。

A normal Windows application implements context menus as real windows, so when they're dismissed by the user all the windows underneath properly receive notification and repaint themselves, so the image of the menu isn't "left behind" anywhere.

The java apps you're having problems with most likely implement context menus by drawing directly on the screen, and when the menus are dismissed the app rolls-its-own and invalidates all the windows underneath it. I'm guessing that this method doesn't invalidate the region occupied by your app because it thinks your window is above it and it doesn't realize your app is transparent (this is speculation - I don't know for sure. if the context menus for these apps look different than the menus for a native app, then this is probably what's going on).

If this is what's happening, there's not much you can do about it. One thing you could do is draw to the screen yourself, instead of using a transparent window. Or you could just have a timer on your form periodically call refresh/invalidate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文