問題描述
如果我創建一個包含兩個項目的菜單(比如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 中禁用的菜單項仍顯示子項的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!