首页 > 开发 > 综合 > 正文

MainMenu的Merge使用

2024-07-21 02:27:54
字体:
来源:转载
供稿:网友
mainmenu merge

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;

            
        }
        private void new_click(object sender,eventargs e)
        {
        
        }
// other codes
}
public class doc : system.windows.forms.form
    {
        public doc()
        {
            menu = new mainmenu();
            menuitem file = menu.menuitems.add("&file");
            file.mergetype = menumerge.mergeitems ;
            file.mergeorder = 0;
            menuitem save=file.menuitems .add ("&save",new eventhandler (save_click));
            save.mergetype =menumerge.mergeitems ;
            save.mergeorder =9;

            menuitem saveas=file.menuitems .add ("&save as",new eventhandler (saveas_click));
            saveas.mergetype =menumerge.mergeitems ;
            saveas.mergeorder =11;
            
            menuitem help = menu.menuitems.add("&help");
            help.mergeorder = 400;    
            help.menuitems.add("&about .net resourcer");
        }
        private void save_click(object sender,eventargs e)
        {
        
        }
        private void saveas_click(object sender,eventargs e)
        {
           messagebox.show ("hello guys");
        }
// other code
}




发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表