cowbird 心有多大,世界有多大

燕八哥 MSN:cowbird2002@hotmail.com

know everything about something and something about everything

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

//动态生成菜单
private void button1_Click(object sender, System.EventArgs e)
{
 //创建顶级菜单
 MenuItem newItem = new MenuItem();
 newItem.Text = "myMenuitem";
 newItem.Index = this.mainMenu1.MenuItems.Count;
 this.mainMenu1.MenuItems.Add(newItem);
 //子菜单一
 MenuItem newSubItem1 = new MenuItem();
 newSubItem1.Text = "mysubitem1";
 newSubItem1.Index = this.mainMenu1.MenuItems.Count;
 newSubItem1.Click += new System.EventHandler(this.MyMenuClick);
 newItem.MenuItems.Add(newSubItem1);
 //子菜单二
 MenuItem newSubItem2 = new MenuItem();
 newSubItem2.Text = "mysubitem2";
 newSubItem2.Index = this.mainMenu1.MenuItems.Count;
 newSubItem2.Click += new System.EventHandler(this.MyMenuClick);
 newItem.MenuItems.Add(newSubItem2);
}

请问如何实现MyMenuClick事件??
private void  MyMenuClick(object sender, System.EventArgs e)
{
        //如果是菜单一点进来的,显示"菜单一"
 //如果是菜单二点进来的,显示"菜单二"
}

posted on 2004-06-24 14:21  cowbird  阅读(1986)  评论(5编辑  收藏  举报