菜单项的工具提示被子菜单下拉列表隐藏

发布于 2024-10-17 08:54:41 字数 485 浏览 2 评论 0原文

我有一个 winforms ContextMenuStrip,它为所有 ToolStripMenuItem 设置了 ToolTipText。

这些菜单项之一“插入操作”具有关联的 ToolStripDropDown 子菜单。当鼠标移动到“插入操作”时,会自动显示下拉菜单,并显示与“插入操作”关联的工具提示,但会被推送到 ContextMenuStrip 和下拉菜单后面的背景。

请参阅此处查看问题图片:http://www.screencast.com/t/GZkeBNcU

我尝试在打开子菜单后以编程方式重新选择“插入操作”,但工具提示不会重新显示在顶部。

有什么想法吗?

或者,有没有一种方法可以仅在单击时显示“插入操作”的子菜单(而不是当鼠标移到其上时自动显示)?我认为应该有一个设置,但一直无法找到它。

感谢您的帮助。

I have a winforms ContextMenuStrip that has ToolTipText set for all of it's ToolStripMenuItem's.

One of these menu items, "Insert Action", has an associated ToolStripDropDown sub-menu. When the mouse is moved to Insert Action, the drop down menu is automatically displayed and the tooltip associated with Insert Action is displayed but pushed to the background behind both the ContextMenuStrip and the dropdown.

See here for a picture of the problem: http://www.screencast.com/t/GZkeBNcU

I have tried programatically re-selecting Insert Action after the sub-menu is opened, but the tooltip will not redisplay on top.

Any ideas?

Alternatively is there a way to only display Insert Action's sub-menu when it is clicked (as opposed to automatically when the mouse is moved over it)? I would think there should be a setting for this, but haven't been able to find it.

Thanks for your help.

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

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

发布评论

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

评论(1

小姐丶请自重 2024-10-24 08:54:41

好吧,这不是很优雅,所以请耐心等待。

似乎 ToolTipText 最初是在顶部绘制的,但是一旦加载下一个 ToolStripMenuItems(在您的情况下由“插入操作”带来的那些),两组 MenuStrip 都会在 ToolTipText 上方找到它们的方式。因此,我的动机是强制 ToolTipText 在新的 MenuStrip 加载后出现。

因此,首先我向 myToolStripMenuItem 添加了一个 DropDownOpened 处理程序,该处理程序将是您命名为“插入操作...”的 MenuItem。

然后,我添加了以下代码,

private void myToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
{
    myToolStripMenuItem.Visible = false;
    myToolStripMenuItem.Visible = true;
    myToolStripMenuItem.ToolTipText = "Tooltip info that you want to see!";
}

它的作用是等待子菜单加载,切换 myToolStripMenuItem 的可见性(这是所有这一切中丑陋的部分),并重置 ToolTipText,强制它在所有内容加载后显示,也高于一切。

但是,如果您尝试悬停并离开两次或更多次,则这样保留会导致一些文本闪烁。只需使用这段代码试一下,您就会明白我的意思。因此,您必须将 ToolTipText 重置为空字符串。当同一个 MenuItem 的 DropDownClosed 事件触发时,我这样做了。

private void myToolStripMenuItem_DropDownClosed(object sender, EventArgs e)
{
    myToolStripMenuItem.ToolTipText = "";
}

现在,ToolTipText 可以准确地出现在我们希望它出现的时间和位置,而不会闪烁。

注意:此方法将导致 ToolTipText 的显示时间比正常情况要长一些。当然,这是因为代码等待下拉菜单加载。此外,切换 myToolStripMenuItem.Visible 有时会导致菜单闪烁。但是,我觉得这比显示您看不到的 ToolTipText 要好得多。

Ok, this isn't terribly elegant so bear with me.

It seems as though the ToolTipText is being drawn on top initially, but once the next ToolStripMenuItems load(The ones brought about by "Insert Action" in your case), both sets of MenuStrips find their way above the ToolTipText. So, my motivation was to force the ToolTipText to appear AFTER the new MenuStrip loads.

So, first I added a DropDownOpened handler to myToolStripMenuItem which would be whatever you named your "Insert Action..." MenuItem.

Then, I added the following code

private void myToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
{
    myToolStripMenuItem.Visible = false;
    myToolStripMenuItem.Visible = true;
    myToolStripMenuItem.ToolTipText = "Tooltip info that you want to see!";
}

What this does is waits for the sub-menu to load, toggles the visibility of myToolStripMenuItem (which is the ugly part in all this), and resets the ToolTipText, forcing it to display after everything is loaded and also on top of everything.

However, leaving it like this would result in some flashing of text if you were to attempt to hover and leave twice or more. Give it a shot with just this code and you will see what I mean. So, you have to reset the ToolTipText to a blank string. I did this when the same MenuItem's DropDownClosed event fires.

private void myToolStripMenuItem_DropDownClosed(object sender, EventArgs e)
{
    myToolStripMenuItem.ToolTipText = "";
}

Now, the ToolTipText appears exactly when and where we want it to appear without ever flickering.

NOTE: This method will result in the ToolTipText taking a little bit longer to show up than normal. This is, of course, because the code waits for the dropdown menu to load. Also, toggling myToolStripMenuItem.Visible will occasionally cause a flicker in the menu. However, I feel that is significantly better than showing a ToolTipText that you can't quite see.

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