private void treeNodes_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
TreeViewHitTestInfo hitTest = treeNodes.HitTest(e.Location);
// Determine whether we should display a context menu or not.
TreeNode currentNode = hitTest.Node;
if (currentNode == null)
return;
INode internalNode = currentNode.Tag as INode;
if (internalNode == null)
return;
// Let's see if we can create a context menu now.
ContextMenuStrip menu = internalNode.CreateContextMenu();
if (menu == null)
return;
/*
Switch to the new node. We do this to make sure that the
event handler can refresh the tree properly.
For example, if the user clicks on a domain, right clicks
on the Accounts node and selects Add, we need to do the following:
1) Ask the user if he wants to save the domain changes (if any)
2) Switch to the Accounts node
3) Show the context menu
Number 2 isn't strictly required here. However, if we don't change
the node, it will be hard for the Account user control to update
the tree in the correct location.
*/
/*if (!ChangeToNode(currentNode))
return;
*/
// Display the context menu.
menu.Show(treeNodes.PointToScreen(e.Location));
}
}