在 .NET 中显示禁用菜单项或替代解决方案的工具提示
我试图在禁用的 ToolStripMenuItem 上显示工具提示,以告知用户其被禁用的原因。
我最初的想法是(因为事件不会在禁用的控件上触发)改为在父 MenuStrip 上拾取 MouseMove 事件,并在禁用的控件上显示工具提示。但该事件似乎没有按预期向上传播父 MenuStrip。这就是它通常的工作方式吧?例如,禁用的文本框事件会向上移动到父面板吗?
附言。我开始觉得这个 UI 设计是个坏主意?有什么更好的方法呢?
I'm trying to display a tooltip on a disabled ToolStripMenuItem, to inform the user why it is disabled.
My initial thought was (as events don't get fired on disabled controls) to pick up the MouseMove event on the parent MenuStrip instead and display the tooltip if over a disabled control. But the event doesn't seem to propagate up the parent MenuStrip as expected. This is how it works usually right? Example, a disabled textbox events would move up to the parent panel?
PS. I'm starting to think this bad idea UI design anyway? What's a better way to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
棘手。我要么接受不可能告诉用户(现在大多数用户很高兴有时由于上下文/所选数据等原因而禁用选项)。或者,您必须启用这些项目,并在用户尝试调用它们时显示弹出窗口或其他警告消息。
Tricky. I'd either accept that it's not possible to tell users (most users these days are happy that sometimes options are disabled because of context/selected data etc). Alternatively, you have to enable these items, and display popups or other warning messages when users try to invoke them.
我不会讨论是否显示糟糕的 UI 设计或不显示详细说明某些内容被禁用的原因的工具提示。
然而,几年前我确实弄清楚了如何对禁用的按钮执行此操作。我知道这不是您的确切问题,但它足够相似,我写的博客文章可能对你有用。
I won't get in to whether it's bad UI design or not to display tooltips detailing the reason something is disabled.
However I did figure out how to do it for disabled buttons a number of years ago. I know it isn't your exact issue, but it is similar enough that the blog post I wrote may be of some use to you.
您应该在包含的
MenuStrip
上设置ShowItemToolTips = true
。即使ToolStripMenuItem
被禁用,工具提示也会显示(但如果整个 MenuStrip 被禁用,则不会显示)。这是一个老问题,所以功能可能已经改变,但OP可能犯了和我一样的错误——我的工具提示没有显示,所以我错误地认为这是因为
ToolStripMenuItem
被禁用了。只是想指出这一点以供将来参考。
You should set
ShowItemToolTips = true
on the containingMenuStrip
. The tooltip will show even when theToolStripMenuItem
is disabled (but it will not show if the entire MenuStrip is disabled).This is an old question, so the functionality might have changed, but OP probably did the same mistake I did - my tooltip was not showing so I wrongly assumed it was because the
ToolStripMenuItem
was disabled.Just wanted to point this out for future reference.