本文介绍了打开和打开问题在ContextMenuStrip中关闭事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个MenuStrip和ContextMenuStrip,在MenuStrip中,我有一个exitToolStripMenuItem1,并且我的表单中有按钮,当我单击按钮时,在右键单击中显示exitToolStripMenuItem1,但是我的exitToolStripMenuItem1在MenuStrip中隐藏了,我该如何解决开幕式ContextMenuStrip的关闭事件?


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;
            }
        }
    }
}

推荐答案


这篇关于打开和打开问题在ContextMenuStrip中关闭事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 00:25