private void MainTreeView_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { // Point where the mouse is clicked. Point p = new Point(e.X, e.Y); // Get the node that the user has clicked. TreeNode node = MainTreeView.GetNodeAt(p); if (node != null) { // Select the node the user has clicked. // The node appears selected until the menu is displayed on the screen. m_OldSelectNode = MainTreeView.SelectedNode; MainTreeView.SelectedNode = node; // Find the appropriate ContextMenu depending on the selected node. string tag = Convert.ToString(node.Tag); switch (tag) { case "Tables": { tablesContextMenu.Show(MainTreeView, p); break; } case "Queries": { queriesMenuStrip.Show(MainTreeView, p); break; } case "Views": { viewsMenuStrip.Show(MainTreeView, p); break; } default: { childNodesMenuStrip.Tag = node.Tag; childNodesMenuStrip.Show(MainTreeView, p); break; } } } } }
//========================================================================== //Node single click //========================================================================== private void MainTreeView_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { MainTreeView.SelectedNode = MainTreeView.GetNodeAt(e.X, e.Y); if (MainTreeView.SelectedNode != null) { TreeViewCStrip.Show(MainTreeView, e.Location); } } }