NotifyIcon app: how to show the context menu?

D

David

Hi,

I am developing a NotifyIcon app with C#. I want to show the context menu
when user left-clicks on the icon, the same as he/she right-clicks on it. In
that event handler, myNotifyIcon_Click(), I call
myNotifyIcon.ContextMenu.Show method. But I am not sure what these two
parameters I should feed.

Thanks in advance.

David
 
M

Morten Wennevik

I call
myNotifyIcon.ContextMenu.Show method. But I am not sure what these two
parameters I should feed.

Well, the first parameter is which control the contextmenu should be tied to. The second parameter is where it should be shown, relative to the upper left corner of a Forms.Control (in case of a form, of the clientrectangle). The problem is, the NotifyIcon isn't a Control even though it can have a context menu, so the show method won't work. You could perhaps overcome this by setting another control as holder of the context menu and calculate the position where it should be shown, but a NotifyIcon has no position either.

I suspect you may have to use platform invokes but I am not sure what methods to use.


Happy coding!
Morten Wennevik [C# MVP]
 

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