如果我创建一个包含两个项目的菜单(比如Item1"和Item2",然后在每个项目下创建两个子项目(1A、1B、2A 和 2B),然后禁用 Item1,我希望 1A 和1B 不会显示.
If I create a menu with two items (say "Item1" and "Item2" and then create two subitems under each one (1A, 1B, 2A and 2B), and then disable Item1, I'd expect that 1A and 1B wouldn't show.
而且,事实上,如果我转到 Item1,他们就不会.除非我接着移至 Item2,等待 2A 和 2B 显示,然后移回 Item1.此时 1A 和 1B 都弹出,完全激活.
And, indeed, if I move onto Item1 they don't. Unless I then move on to Item2, wait for 2A and 2B to show, and then move back to Item1. At which point 1A and 1B both pop up, fully active.
这是一个已知的错误吗?这是我可以解决的问题吗?有什么建议吗?
Is this a known bug? Is it something I can work around? Any suggestions?
用户希望能够看到当前被禁用的东西,或者我只是让东西不可见.遗憾的是,这不是我们可以轻松使用的选项.
The users want to be able to see the things that are currently disabled, or I'd just make things invisible. Sadly, this isn't an option we can easily use.
我可以确认在 MenuStrip for Framework 2.0、3.5 和 4.0 中会发生这种情况.我唯一合理的解决方法是将 Visible
属性设置为 false
,因此该项目根本不会出现.不理想,但比让子项目可访问要好.
I can confirm that this occurs with the MenuStrip for Framework 2.0, 3.5 and 4.0. The only reasonable workaround that I have is to set the Visible
property to false
, so the item does not appear at all. Not Ideal, but better than having the sub-items accessible.
当然你也可以创建一个函数来递归禁用所有子项,这样即使出现了,也至少是禁用的,你需要保持之前的状态,以确保以后不会重新启用一个实际上打算被禁用的子项目等.文档表明这实际上是发生了什么,但事实并非如此,即使父项目被禁用,子项目仍然保持启用状态.
Of course you can also create a function that will recursively disable all child items, that way even if they appear, they are at least disabled, you will need to maintain the previous state to ensure that you do not later re-enable a child item that is actually inteded to be disabled etc. The documentation indicates that this is actually what happens, but that is not the case, sub-items remain enabled even when the parent item is disabled.
这篇关于Winforms 中禁用的菜单项仍显示子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!