Need to left click on a NotifyIcon?

17 09 2008

I’m working on a client/server application that uses touch screens for user input. The app uses the NotifyIcon class to minimise the app to the tray when not required with a ContextMenuStrip to handle right click operations, herin lies the problem – touch screens are using touch, not mice to interface with the application hence you cannot right click!

Solution is the code below, it allows you to left click (or touch) the trayicon and still display the ContextMenu. What a PIA it was to find this!

using System.Reflection;

private void notifyIcon1_MouseUp(object sender, MouseEventArgs e)
{

if (e.Button == MouseButtons.Left)
{

MethodInfo mi = typeof(NotifyIcon).GetMethod(“ShowContextMenu”, BindingFlags.Instance | BindingFlags.NonPublic);
mi.Invoke(notifyIcon1,
null);

}
}

Advertisements