在非焦点 ToolStripItem 上显示工具提示
当您将鼠标悬停在 ToolStripItems 上时,它们会显示活动突出显示,即使它们所在的表单未处于焦点状态。 但是,除非表单获得焦点,否则它们不会显示工具提示。 我见过 ToolStrip 'click-though' hack 。 任何人都知道如何使 ToolStripButton 在其父窗体未获得焦点时显示其工具提示?
谢谢!
ToolStripItems show Active highlighting when you mouse over them, even if the form they are in is not in focus. They do not, however, show their tooltips, unless the form is focused. I have seen the ToolStrip 'click-though' hack. Anyone know how to make a ToolStripButton show its tooltip when its parent form is not in focus?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
问题在于 ToolStrip“控件”(如 ToolStripButton 或 ToolStripDropDownButton)不继承自 Control。 现在,我通过每当用户将鼠标悬停在按钮上时聚焦 ToolStrip 来解决该问题。 该按钮的 MouseHover 事件触发得太晚了——在“显示工具提示”代码运行之后,因此我扩展了 ToolStripDropDownButton 类并使用了我的新按钮。 此方法应该适用于继承自 ToolStripItem 的任何其他类似按钮的类
The problem is that the ToolStrip "controls" like ToolStripButton or ToolStripDropDownButton don't inherit from Control. For now I addressed the problem by focusing the ToolStrip whenever a user hovers over a button. The button's MouseHover event is fired too late -- after the "show tooltip" code would have been run, so I extended the ToolStripDropDownButton class and used my new button. This method should work for any of the other button-like classes inheriting from ToolStripItem
也许此代码中的两种方法之一会引导您朝正确的方向前进...
第一种方法的问题是您无法直接将其设置为按钮,它不继承自 Control,并且工具提示不会'除非您越过条带但未越过按钮,否则不会出现。
第二个(注释掉的方式)的问题是它根本不显示。 不太清楚为什么,但也许你可以调试它。
Perhaps one of the two approaches in this code will kick you off in the right direction...
The problem with the first is you can't set it to the button directly, it doesn't inherit from Control, and the tooltip won't show up unless you're over the strip but not over a button.
The problem with the second (commented out way) is it doesn't display at all. Not quite sure why, but maybe you can debug it out.
我尝试了一些事情,发现这是最简单的,
当我创建toolstripbutton项目时,我向其悬停事件添加了一个事件处理程序:
然后是事件处理程序:
这工作得很好,尽管我确实注意到当您将鼠标悬停在上面时有一个微小的初始延迟第一次使用工具条
i tried a few things and found this to be the simplest
when i create the toolstripbutton items i added an event handler to its hover event:
then the event handler:
this works really nicely, although i do notice a tiny initial delay when you hover over the toolstrip for the 1st time
我试图做同样的事情,并确定这将是相当具有挑战性且不值得的。 原因是,.NET 代码在内部专门设计为仅在窗口处于活动状态时显示工具提示 - 他们在 Win32 级别对此进行检查,因此很难伪造代码。
以下是 ToolTip.cs 中检查“GetActiveWindow()”并返回 false 的代码片段。 您可以看到代码中的注释“ToolTips should be displayed only on active Windows”。
顺便说一句,您可以使用 Visual Studio 2008 查看 .NET BCL 的所有源代码,以下是我使用的说明:
http://blogs.msdn.com/sburke/archive/2008/01/16/配置-visual-studio-to-debug-net-framework-source-code.aspx
I was trying to do the same thing and determined it was going to be pretty challenging and not worth it. The reason is that internally, the .NET code is specifically designed to only show the tooltip if the window is active - they are checking this at a Win32 level so its going to be hard to fake the code out.
Here is the code snippet in ToolTip.cs that checks "GetActiveWindow()" and returns false. You can see the comment in the code "ToolTips should be shown only on active Windows."
By the way, you can see all the source code for the .NET BCL with Visual Studio 2008, here are the instructions I used:
http://blogs.msdn.com/sburke/archive/2008/01/16/configuring-visual-studio-to-debug-net-framework-source-code.aspx