hyd*_*gen 3 .net c# notifyicon contextmenustrip winforms
我有一个ContextMenuStrip分配给NotifyIcon,这适用于右键单击罚款.
如何连接鼠标单击事件以告知NotifyIcon显示其ContextMenuStrip?
private void taskbarIcon_MouseClick(object sender, MouseEventArgs e)
{
switch (e.Button)
{
case MouseButtons.Left:
// What could I use here?
break;
default:
break;
}
}
Run Code Online (Sandbox Code Playgroud)
Mik*_*nen 10
您应该能够使用以下代码:
if (e.Button == MouseButtons.Left)
{
MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu",
BindingFlags.Instance |BindingFlags.NonPublic);
mi.Invoke(taskbarIcon, null);
}
Run Code Online (Sandbox Code Playgroud)