Skip to content

Instantly share code, notes, and snippets.

@jcorderodr
Created July 28, 2017 00:41
Show Gist options
  • Select an option

  • Save jcorderodr/2ea6ed89bc91a1d1add086ae1b40af2b to your computer and use it in GitHub Desktop.

Select an option

Save jcorderodr/2ea6ed89bc91a1d1add086ae1b40af2b to your computer and use it in GitHub Desktop.
Set ToolStripItem & ToolStripMenuItem Visibility C#
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