NotifyIcon app: how to show the context menu?

  • Thread starter Thread starter David
  • Start date Start date
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
 
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]
 
Back
Top