1. Source Code
Private void toolstripmenuitem#click (object sender, EventArgs e)
{
// Click expand (close) to show other events
Switch (I)
{
Case 1:
This. Set the password ToolStripMenuItem. Visible = false;
This. Add User ToolStripMenuItem. Visible = false;
This. forgot password ToolStripMenuItem. Visible = false;
This. Change the password ToolStripMenuItem. Visible = false;
This. Employee input ToolStripMenuItem. Visible = false;
I = 2;
This. Operate ToolStripMenuItem. ShowDropDown ();
Break;
Case 2:
This. Set the password ToolStripMenuItem. Visible = true;
This. Add User ToolStripMenuItem. Visible = true;
This. forgot password ToolStripMenuItem. Visible = true;
This. Change the password ToolStripMenuItem. Visible = true;
This. Employee input ToolStripMenuItem. Visible = true;
I = 1;
This. Operate ToolStripMenuItem. ShowDropDown ();
Break;
}
}
2. If the menu is Visible only when the initial form is used, you only need to set the Visible attribute of the menu item,
3. The special point here is this. Operate ToolStripMenuItem. ShowDropDown ();
When this sentence is left blank, the system automatically closes the menu after clicking it. It is deemed that the execution of the button event has ended, and the menu cannot be refreshed. You need to click the menu to observe it. After this sentence is added, the menu is updated and not closed, you can directly view the menu changes.