How to get the location of the mouse position when clicking on a trayicon?

L

Lothar Behrens

Hi,

I have implemented a notify icon and the mouse click handler. But when
I read out the e.Location or e.X and e.Y I get the location of the
upper left corner (0, 0).

How to get the correct location?

private void notifyIcon1_MouseClick(object sender,
MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
// Another popup menu implementation.
popupMenuNotifyIcon.ShowPopup(new Point(e.X, e.Y));
}
}


Thanks

Lothar
 
J

Jeff Johnson

I have implemented a notify icon and the mouse click handler. But when
I read out the e.Location or e.X and e.Y I get the location of the
upper left corner (0, 0).

How to get the correct location?

private void notifyIcon1_MouseClick(object sender,
MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
// Another popup menu implementation.
popupMenuNotifyIcon.ShowPopup(new Point(e.X, e.Y));
}
}

Don't display the menu manually. Just assign a ContextMenu object to the
ContextMenu property of the NotifyIcon and Windows will automatically
display it when the icon is right-clicked. Or at least that's what MSDN
seems to be saying....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top