Created
July 28, 2017 00:41
-
-
Save jcorderodr/2ea6ed89bc91a1d1add086ae1b40af2b to your computer and use it in GitHub Desktop.
Set ToolStripItem & ToolStripMenuItem Visibility C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void SetVisibleProperty(bool visible = false, params ToolStripItem[] controls) | |
| { | |
| foreach (var ctrl in controls) | |
| { | |
| ctrl.Enabled = visible; | |
| if (ctrl is System.Windows.Forms.ToolStripMenuItem) | |
| { | |
| var menu = ctrl as System.Windows.Forms.ToolStripMenuItem; | |
| if (menu.DropDownItems.Count > 0) | |
| { | |
| SetVisiblePropertie(visible, menu.DropDownItems.OfType<ToolStripItem>().Where(i => !(i is ToolStripSeparator)).ToArray()); | |
| } | |
| } | |
| } | |
| } | |
| // usage1: SetVisibleProperty(false, adminToolStripMenuItem); | |
| // usage2: SetVisibleProperty(true, fileToolStripMenuItem); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment