Winforms 中禁用的菜单项仍显示子项

Disabled menu items in Winforms still show subitems(Winforms 中禁用的菜单项仍显示子项)
本文介绍了Winforms 中禁用的菜单项仍显示子项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

如果我创建一个包含两个项目的菜单(比如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 中禁用的菜单项仍显示子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

ActiveDirectory error 0x8000500c when traversing properties(遍历属性时 ActiveDirectory 错误 0x8000500c)
search by samaccountname with wildcards(使用通配符按 samaccountname 搜索)
Get the list of Groups for the given UserPrincipal(获取给定 UserPrincipal 的组列表)
Can you find an Active Directory User#39;s Primary Group in C#?(你能在 C# 中找到 Active Directory 用户的主要组吗?)
Query From LDAP for User Groups(从 LDAP 查询用户组)
How can I get DOMAINUSER from an AD DirectoryEntry?(如何从 AD DirectoryEntry 获取 DOMAINUSER?)