1
Answer

Get and Set of ToolStripMenuItem.Visible property has different functionality

Jagg

Jagg

14y
6.3k
1
Hi everyone,

If I have a nested menu as such:
[Main]
[Sub1]

For some reason I cannot read the correct value of the ToolStripMenuItem.Visible property of [Sub1], it returns false if the menu is closed, and true if the menu is open.
BUT
1: I can set it manually to false, and the menu item becomes invisible. I open the menu and it is no longer there.
2: I can set it manually to true, and the menu item becomes visible again. I open the menu and it is there again.

So whenever I read the state of the Visible property, it does not return whether or not the menu item will be displayed when I open the menu, it returns whether or not it is being displayed right now. This is very ambiguous as the same variable inconsistently controls 2 different behaviors, its read and write have different functionality. (I figured this was bad practice, very bad practice...)

I really need to be able to determine whether at least one of the DropDownItems of a ToolStripMenuItem is visible, in order to set the visibility of the item itself.

Any help? (The problem is easily reproduced, make a form with a MenuStrip, add a menu item with a child menu item and test setting and getting its visibility)

Jagg
Answers (1)