我正在尝试将几个 ContextMenu 项目合并为一个。目前,我正在使用单独的 MenuItem 来工作。有没有一种方法可以将所有这些 MenuItems 组合成一个同时能够在用户单击不同的 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)
{
}