How to programmatically add ContextMenu icon to taskbar icon?

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 a right-click event handler for the tray icon?

I tried the following:

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 is declared as,

 NotifyIcon.MouseRightClick += new MouseButtonEventHandler(NotifyIcon_MouseRightClick); 
+7
c # wpf contextmenu right-click trayicon
source share
1 answer

Right-click context menu automatically, no need to process it. Just create your menu and assign it NotifyIcon.ContextMenu .

+15
source share

All Articles