/// <summary> /// 鼠标动作(非顶层) /// </summary> /// <param name="e"></param> private void trvData_MouseClick_NotTop(MouseEventArgs e) { if (MDataViewInfo.IsView) { return; //View是只读的 } if (e.Button != MouseButtons.Right) { return; } contextMenuStripMain = new ContextMenuStrip(); contextMenuStripMain.Items.Add(AddElementToolStripMenuItem.Clone()); contextMenuStripMain.Items.Add(ModifyElementToolStripMenuItem.Clone()); contextMenuStripMain.Items.Add(DropElementToolStripMenuItem.Clone()); contextMenuStripMain.Items.Add(CopyElementToolStripMenuItem.Clone()); contextMenuStripMain.Items.Add(CutElementToolStripMenuItem.Clone()); contextMenuStripMain.Items.Add(PasteElementToolStripMenuItem.Clone()); trvData.DatatreeView.ContextMenuStrip = contextMenuStripMain; contextMenuStripMain.Show(trvData.DatatreeView.PointToScreen(e.Location)); }
/// <summary> /// 鼠标动作(顶层) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void trvData_MouseClick_Top(object sender, MouseEventArgs e) { if (MDataViewInfo.IsView) { return; //View是只读的 } if (_isNeedChangeNode) { //在节点展开和关闭后,不能使用这个方法来重新设定SelectedNode trvData.DatatreeView.SelectedNode = trvData.DatatreeView.GetNodeAt(e.Location); } _isNeedChangeNode = true; if (trvData.DatatreeView.SelectedNode == null) { return; } SetCurrentDocument(trvData.DatatreeView.SelectedNode, RuntimeMongoDbContext.GetCurrentCollection()); if (trvData.DatatreeView.SelectedNode.Level == 0) { if (e.Button == MouseButtons.Right) { contextMenuStripMain = new ContextMenuStrip(); //允许删除 DelSelectRecordToolToolStripMenuItem.Enabled = true; contextMenuStripMain.Items.Add(DelSelectRecordToolToolStripMenuItem.Clone()); //允许添加 AddElementToolStripMenuItem.Enabled = true; contextMenuStripMain.Items.Add(AddElementToolStripMenuItem.Clone()); //允许粘贴 PasteElementToolStripMenuItem.Enabled = true; contextMenuStripMain.Items.Add(PasteElementToolStripMenuItem.Clone()); trvData.DatatreeView.ContextMenuStrip = contextMenuStripMain; contextMenuStripMain.Show(trvData.DatatreeView.PointToScreen(e.Location)); } } else { //非顶层元素 trvData_MouseClick_NotTop(e); } }