我想以编程方式在我的托盘图标上添加一个上下文菜单,这样当我右键单击托盘图标时,它应该显示菜单。如何为托盘图标编写右键单击事件处理程序?
我试过以下内容:
private void Icon_MouseRightClick(object sender, MouseButtonEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left) // shows error ate button
{
return;
}
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
// code for adding context menu
}
}
声明Eventhandler为,
NotifyIcon.MouseRightClick += new MouseButtonEventHandler(NotifyIcon_MouseRightClick);