コード例 #1
0
        /// <summary>
        /// 动态右键菜单,选择菜单之后执行对应功能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NewStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            var now = (ContextMenuStrip)sender;

            now.Close();
            var node = this.tv_menu.SelectedNode;

            if (node == null)
            {
                MessageBox.Show("请选择菜单");
                return;
            }
            var stripText  = e.ClickedItem.Text.GetEunmInDesciption(typeof(NodeMenu));
            var descrition = node.Text; //描述
            var code       = node.Tag;  //code编码
            var codeParent = node.Name; //父级编号
            Add add        = null;
            var _code      = code == null ? null : code.ToString();

            switch ((NodeMenu)stripText)
            {
            case NodeMenu.addchildren:
                add = new Add(_code, NodeMenu.addchildren);
                break;

            case NodeMenu.update:
                add = new Add(_code);
                break;

            case NodeMenu.remove:
                Remove(code);
                break;

            case NodeMenu.add:
                add = new Add(codeParent == null ? null : codeParent.ToString(), NodeMenu.add);
                break;

            case NodeMenu.addFunc:
                AddFunc addFunc = new AddFunc(_code);
                addFunc.StartPosition = FormStartPosition.CenterScreen;
                var result = addFunc.ShowDialog();
                addFunc.Dispose();
                break;

            case NodeMenu.initFunc:
                MenuStripFactory.InItFunc(_code);
                MessageBox.Show("操作成功");
                break;

            default:
                break;
            }
            if (add != null)
            {
                add.StartPosition = FormStartPosition.CenterScreen;
                var result = add.ShowDialog();
                add.Dispose();
            }
            LoadTree();
            LoadMenuList(code);
            this.tv_menu.SelectedNode = node;
        }