I have a simple tray application in c#. What i want to do is to open the context menu on left click. At the moment it is only opening at the right click. This seems to be the standart behaviour.
I managed to react on left click but i don't know how to open the contextMenu programatically. Any Ideas?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Drawing;
namespace trackingCore
{
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
NotifyIcon notifyIcon1 = new NotifyIcon();
ContextMenu contextMenu1 = new ContextMenu();
MenuItem menuItem0 = new MenuItem();
MenuItem menuItem1 = new MenuItem();
MenuItem menuItem2 = new MenuItem();
contextMenu1.MenuItems.AddRange(new MenuItem[] { menuItem0 });
contextMenu1.MenuItems.AddRange(new MenuItem[] { menuItem1 });
contextMenu1.MenuItems.AddRange(new MenuItem[] { menuItem2 });
menuItem0.Index = 0;
menuItem0.Text = "open test";
menuItem0.Click += new EventHandler(menuItem1_Click);
menuItem1.Index = 1;
menuItem1.Text = "stop test";
menuItem1.Click += new EventHandler(menuItem1_Click);
menuItem2.Index = 2;
menuItem2.Text = "close test";
menuItem2.Click += new EventHandler(menuItem1_Click);
notifyIcon1.Icon = new Icon("test.ico");
notifyIcon1.Text = "testitest";
notifyIcon1.ContextMenu = contextMenu1;
notifyIcon1.Click += new EventHandler(menuItem1_Click);
notifyIcon1.Visible = true;
Application.Run();
notifyIcon1.Visible = false;
}
private static void menuItem1_Click(object Sender, EventArgs e)
{
Application.Exit();
}
private static void iconClick(object Sender, EventArgs e)
{
Console.Write("open context menu with left click");
}
}
}
That are some solutions that say contextMenu1.Show would be the solution. However the show functions needs two parametern and I can't tell which ones would be correct. It used to be only one paramter. Any ideas?