0

I am building winform application without any form shown (opacity of form is 0 and ShowInTaskbar property is false). It is accessible only from tray Notify icon. When users clicks with left mouse button on it, the contextMenustrip menu will be show. Because I want to detect LEFT mouse button click I can't use ContextMenu Property of NotifyIcon.

I would like, that if users clicks whenever out of the menu, it should hide. I don't have any idea how I can do that...

If I have shown form, I could detect Deactivate form event and then hide my menu, but in described situation it looks harder.

Alexander Stepaniuk
  • 6,217
  • 4
  • 31
  • 48
Viper
  • 597
  • 1
  • 8
  • 24
  • 1
    possible duplicate of [Invoke NotifyIcon's Context Menu](http://stackoverflow.com/questions/2208690/invoke-notifyicons-context-menu) – Hans Passant Jan 01 '13 at 19:10
  • @HansPassant Thank you. I couldn't find suitable topic. It works. – Viper Jan 01 '13 at 19:40
  • @HansPassant Thank you. I couldn't find suitable topic. It works. According to your advice I have used reflection to call ShowContextMenu() method in MouseUp event. What I did in different way is that I have two ContextMenuStrip menus: one connected with ContextMenuProperty of NFI and second, not connected with NIF. Invoking ShowContextMenu() with reflection and later manually showing unconnected menu resolves the problem, despite that I don't connect this menu in NIF ContextMenu property. Could you explain why? – Viper Jan 01 '13 at 19:47

1 Answers1

0

1) Instead of setting opacity to 0 better set WindowState = FormWindowState.Minimized

2) You cant detect mouse clicks outside of your program as they are controlled by other programs or your OS, but handling Leave or MouseLeave event should help you

VladL
  • 12,769
  • 10
  • 63
  • 83