When a user logs into my application, there are some menu items that I don't want every user to see. So I would like to either disable or make invisible the menu item. For example fileToolStripMenuItem
is the first item in my menuStrip
, when I try:
fileToolStripMenuItem.Enabled = false;
- this does not work
menuStrip.Items[0].Enabled = false;
- this does work
Can anyone enlighten me as to the difference here?
Also, I would like to be able to disable a drop down item from one of the menu items, but I cannot do that either.
Here's the code:
public Form1()
{
InitializeComponent();
// bunch of other code here
if (!login.ValidatedUser)
{
menuStrip1.Items[0].Visible = false; // this works
toolsToolStripMenuItem.Visible = false; // this does not
btnStartResourceManager.Enabled = false;
listAvailableSizes.Enabled = true;
panelPicSet.Enabled = true;
}
}
Use the specific name of your menu item and change its Visible property. i.e.
For Sub Items, just right click on the item and see its name In Design Section in Properties Window. In my case below
addNewToolStripMenuItem1
.fileToolStripMenuItem.Enabled = false;
works as expected. I think you trying to disable it before InitializeComponent(); call.