简体   繁体   English

ToolTipText 在控件下弹出

[英]ToolTipText popping up underneath control

I've got a .NET app with a NotifyIcon that sits in the systray.我有一个 .NET 应用程序,其 NotifyIcon 位于系统托盘中。 That nic has a ContextMenuStrip and that ctx mnu has several ToolStripMenuItems in it.那个 nic 有一个 ContextMenuStrip 并且那个 ctx mnu 里面有几个 ToolStripMenuItems。 Most of them have their ToolTipText set at run-time.他们中的大多数都在运行时设置了 ToolTipText。 The problem is that most of the time, the ttp pops up UNDER the mnu item.问题是大多数时候,ttp 会在 mnu 项下弹出。 It will either be mostly or entirely obscured by the mnu item itself.它将被 mnu 项目本身大部分或完全遮挡。 Depending on where I move my mouse, sometimes the ttp pops up over the mnu and you can see it entirely, but most of the time it's not.根据我移动鼠标的位置,有时 ttp 会在 mnu 上弹出,您可以完全看到它,但大多数时候不是。

How it's even possible for a ttp to pop up under its control (thus rendering it useless) is beyond me, but does anyone know how to stop this behavior?一个 ttp 怎么可能在它的控制下弹出(从而使它变得无用)超出了我的范围,但是有谁知道如何阻止这种行为?

Here's the code that sets it.这是设置它的代码。 Pretty straight-forward:非常直接:

Dim mnu As ToolStripMenuItem = ctmMain.Items.OfType(Of ToolStripMenuItem).Where(Function(m) m.Tag IsNot Nothing AndAlso m.Tag = "EM_" & Account).First
mnu.ToolTipText = dt.Rows(0)("Display")

I've tried cycling ShowItemToolTips on the ctx mnu (and a few other random things), but nothing changes this behavior.我试过在 ctx mnu 上循环 ShowItemToolTips (以及其他一些随机的东西),但没有任何改变这种行为。 I either need to fix this, or find some simple alternative to the ToolStripMenuItem.ToolTipText.我要么需要解决这个问题,要么找到 ToolStripMenuItem.ToolTipText 的一些简单替代方案。

Well, I figured this out midstream but I figured I'd post it for anyone else who runs into this behavior.好吧,我在中途发现了这一点,但我想我会把它发布给遇到这种行为的其他人。 ToolTipText wasn't viable no matter what I tried, but I was able to add a ToolTip control to the main form and hijack that.无论我尝试什么,ToolTipText 都不可行,但我能够将 ToolTip 控件添加到主窗体并劫持它。 I set the ContextMenu's ShowItemToolTips to False and handled the display of the ToolTipText text manually.我将 ContextMenu 的 ShowItemToolTips 设置为 False 并手动处理 ToolTipText 文本的显示。

You can't use a ToolTip control with a ToolStripMenuItem (because the latter isn't a control), however you can use it with a ContextMenuStrip, which is the Parent control of the mnu itms.您不能将 ToolTip 控件与 ToolStripMenuItem 一起使用(因为后者不是控件),但是您可以将它与 ContextMenuStrip 一起使用,后者是 mnu 的父控件。 So, I added Handlers for the MouseEnter and MouseLeave events of each ToolStripMenuItem and used those to display/hide the ToolTipText for each mnu item.因此,我为每个 ToolStripMenuItem 的 MouseEnter 和 MouseLeave 事件添加了处理程序,并使用它们来显示/隐藏每个 mnu 项的 ToolTipText。 This got rid of the pop-under issue for the most part.这在很大程度上消除了弹出问题。 There are still occasional odd behaviors, but it's a viable solution.仍然偶尔会出现奇怪的行为,但这是一个可行的解决方案。

Sub LoadMenus(acct As ToolStripMenuItem)
    AddHandler acct.MouseEnter, AddressOf EMToolTipShow
    AddHandler acct.MouseLeave, AddressOf EMToolTipHide
End Sub
Private Sub EMToolTipShow(sender As Object, e As EventArgs)
    ttpEM.Show(sender.ToolTipText, sender.GetCurrentParent())
End Sub
Private Sub EMToolTipHide(sender As Object, e As EventArgs)
    ttpEM.Hide(sender.GetCurrentParent())
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM