Winforms 中禁用的菜单项仍显示子项
- 作者: 小可爱的可爱
- 来源: 51数据库
- 2022-10-20
问题描述
如果我创建一个包含两个项目的菜单(比如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.
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
