WinForms中动态给treeView的节点添加ContextMenuStrip,并绑定Click事件
程序员文章站
2024-02-01 18:05:46
生成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"); }
下一篇: MQ相关面试题