Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,i made a MenuStrip and ContextMenuStrip,in MenuStrip i have a exitToolStripMenuItem1 and i have button in my form,when i click on button exitToolStripMenuItem1 was show in Right click but my exitToolStripMenuItem1 hide from MenuStrip,how can i solve it with opening & closing events of ContextMenuStrip?


namespace Menu
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ContextMenuStrip.Items.Add(exitToolStripMenuItem1);
        }

        private void ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem itmCurrent = (ToolStripMenuItem)sender;

            switch (itmCurrent.Name)
            {
                case "exitToolStripMenuItem1":

                    System.Windows.Forms.DialogResult interactionResult;
                    interactionResult = MessageBox.Show("Are you sure you want to exit?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

                    if (interactionResult == System.Windows.Forms.DialogResult.Yes)
                        Application.Exit();

                    break;
            }
        }
    }
}
Posted

1 solution

What you need to do is to include the toolstripmenuitem in the design.

Set properties to visible false and enabled false

On click set the properties of visible and enabled to true.

that works for both the menu strip and the context menu strip
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900