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

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: