windows form的程序使用菜单mainmenu是,有时需要根据操作隐藏或显示menuitem,另外窗体类和关联的菜单项事件在一个class中,结构清晰。
do like this: class form1: form{ public form1() { // // required for windows form designer support // initializecomponent(); ismdicontainer = true; menu = new mainmenu(); menuitem file = menu.menuitems.add("&file"); file.mergetype = menumerge.mergeitems; file.mergeorder = 0; menuitem filenew = file.menuitems.add("&new", new eventhandler(new_click)); filenew.shortcut = shortcut.ctrln; filenew.mergeorder = 10;