我想将菜单项动态添加到systray应用程序。我已经有一个“退出”和“添加更多”菜单。我想在运行时添加其他菜单时单击“添加更多”来添加更多菜单。 例如,当我单击“添加更多”时,它将自动向托盘应用添加新的menuItem。
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
NotifyIcon notify = new NotifyIcon();
notify.ContextMenuStrip = MainContextMenu();
notify.Icon = new Icon("Led.ico");
notify.Visible = true;
Application.Run();
}
private static ContextMenuStrip MainContextMenu()
{
ContextMenuStrip ConextMenuApp = new ContextMenuStrip();
ConextMenuApp.Items.Add("Add More", null, new EventHandler(AddMoreMenus));
ConextMenuApp.Items.Add("-");
ConextMenuApp.Items.Add("Exit", null, new EventHandler(Exit_Click));
return ConextMenuApp;
}
private static ContextMenuStrip AddMoreMenus(Object sender, EventArgs e)
{
ContextMenuStrip AddNewMenu = new ContextMenuStrip();
AddNewMenu.Items.Add("Menu One Addedd");
return AddNewMenu;
}
private static void Exit_Click(Object sender, EventArgs e)
{
Application.Exit();
}
}
}
答案 0 :(得分:0)
实际上有很多方法可以执行此操作,但是最简单的方法是对func mapViewRegionIsChanging(_ mapView: MGLMapView) {
print(mapView.zoomLevel, " Cenetr -<<<<")
}
或MenuStrip
项保留 Reference 并将其传递。
尽管老实说,只是选择你的毒药。
MenuStrip