生成ContextMenuStrip 將docMenu添加到treeView中去 添加綁定事件(函數名稱要和上面綁定時候的名稱一樣) ...
生成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"); }