本文介绍了如何以编程方式将ContextMenu添加到系统任务栏图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式向我的任务栏图标添加一个上下文菜单,以便当我右键单击任务栏图标时,它应该向我显示菜单。如何为我的任务栏图标编写右键单击事件处理程序?

I want to programmatically add a context menu to my tray icon, so that when I right-click on the tray icon, it should show me the menu.How should I write the right-click event handler for my tray icon?

我尝试了以下操作:

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,

Declared Eventhandler as,

NotifyIcon.MouseRightClick += new MouseButtonEventHandler(NotifyIcon_MouseRightClick);


推荐答案

右键单击上下文菜单是自动的,不需要处理它。只需构建菜单并将其分配给。

Context menu on right-click is automatic, no need to handle it. Just build your menu and assign it to NotifyIcon.ContextMenu.

这篇关于如何以编程方式将ContextMenu添加到系统任务栏图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 05:53