轉自http://www.cnblogs.com/luluping/archive/2010/03/03/1677206.html html
(1)要向窗體添加一個TreeView控件c#
(2)再添加一個ContextMenuStrip控件;spa
(3)就要給TreeView添加一個MouseDown事件,代碼以下:code
private void treeView1_MouseDown(object sender, MouseEventArgs e) ...{ if (e.Button == MouseButtons.Right)//判斷你點的是否是右鍵 ...{ Point ClickPoint = new Point(e.X, e.Y); TreeNode CurrentNode = treeView1.GetNodeAt(ClickPoint); if (CurrentNode != null)//判斷你點的是否是一個節點 ...{ switch (CurrentNode.Name)//根據不一樣節點顯示不一樣的右鍵菜單,固然你可讓它顯示同樣的菜單 ...{ case "errorUrl": CurrentNode.ContextMenuStrip = contextMenuStripErrorUrl; break; } treeView1.SelectedNode = CurrentNode;//選中這個節點 } } }