将几个ContextMenu项合并为一个

时间:2012-11-21 10:21:01

标签: c# wpf

我正在尝试将多个ContextMenu项合并为一个。目前,我使用单独的MenuItem工作。有没有办法将所有这些MenuItem组合成一个WHILE,当用户点击不同的MenuItems时,能够控制每个事件触发器?

NotifyIcon notifyIcon = new NotifyIcon();
        System.Windows.Forms.ContextMenu contextMenu = new System.Windows.Forms.ContextMenu();


        System.Windows.Forms.MenuItem ChangeDetailsMenu = new System.Windows.Forms.MenuItem();
        ChangeDetailsMenu.Text = "Change Contact Details";
        ChangeDetailsMenu.Click += ChangeContactDetails;

        System.Windows.Forms.MenuItem ChangeKinectAngleMenu = new System.Windows.Forms.MenuItem();
        ChangeKinectAngleMenu.Text = "Change Kinect Angle";
        ChangeKinectAngleMenu.Click += ChangeKinectAngle;

        System.Windows.Forms.MenuItem exitMenu = new System.Windows.Forms.MenuItem();
        exitMenu.Text = "Exit";
        exitMenu.Click += ExitHandler;

        contextMenu.MenuItems.Add(exitMenu);
        contextMenu.MenuItems.Add(ChangeDetailsMenu);
        contextMenu.MenuItems.Add(ChangeKinectAngleMenu);

        Icon icon = new Icon("kse.ico");
        notifyIcon.ContextMenu = contextMenu;
        notifyIcon.Icon = icon;
        notifyIcon.Visible = true;

private void ExitHandler(object sender, EventArgs e)
    {

        notifyIcon.Visible = false;
        System.Windows.Application.Current.Shutdown();
    }



    private void ChangeContactDetails(object sender, EventArgs e)
    {

    }

    private void ChangeKinectAngle(object sender, EventArgs e)
    {

    }

0 个答案:

没有答案