0

I´m trying to open a small WPF application when right clicking on a NotifyIcon.
I added the NotifyIcon by adding the System.Windows.Forms to the resources and this lines:

System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
ni.Icon = new System.Drawing.Icon(@"C:\...\icon.ico");
ni.Visible = true;

The way I´ve tried to implement the right click event:

ni.Click += delegate (object sender, System.EventArgs e)
{
  if (e.Equals(MouseButtons.Right))
  {
    MessageBox.Show("Haha", "haha", MessageBoxButton.OK);
  }
}

Both code snippets are in the MainWindow() function.

SideSky
  • 313
  • 3
  • 15
  • 1
    Do you want to [show context menu](https://stackoverflow.com/q/17946380/1997232)? – Sinatr May 27 '20 at 07:05
  • 1
    Try to use `MouseClick` (or some other mouse event) instead of `Click`. – Sinatr May 27 '20 at 07:07
  • Yes it is the context menu, thank you! – SideSky May 27 '20 at 08:06
  • 1
    Does this answer your question? [How to add ContextMenu to the system tray icon programmatically?](https://stackoverflow.com/questions/17946380/how-to-add-contextmenu-to-the-system-tray-icon-programmatically) – Keith Stein May 27 '20 at 20:00

1 Answers1

0

It is called the context menu

private void Form1_Load(object sender, EventArgs e)
{
    notifyIcon1.ContextMenu = contextMenu1;
}
SideSky
  • 313
  • 3
  • 15