生成ContextMenuStrip
var docMenu = new ContextMenuStrip();
ToolStripMenuItem deleteMenuItem = new ToolStripMenuItem();
deleteMenuItem.Text = "Delete";
deleteMenuItem.Click += new EventHandler(deleteMenuItem_Click); //给添加的ContextMenuStrip绑定click事件
docMenu.Items.AddRange(new ToolStripMenuItem[] { deleteMenuItem });
将docMenu添加到treeView中去
DataTreeView.Nodes[0].ContextMenuStrip = docMenu;
添加绑定事件(函数名称要和上面绑定时候的名称一样)
private void deleteMenuItem_Click(object sender, EventArgs e) { MessageBox.show("click delete"); }