System tray icon with c# Console Application won't show menu

前端 未结 4 1410
名媛妹妹
名媛妹妹 2021-01-02 15:32

I\'ve got a small C# (.NET 4.0) Console Application that I\'d like the user to be able to interact by showing a menu when they right-click the System Tray icon. I can add an

4条回答
  •  生来不讨喜
    2021-01-02 16:21

    Try adding this after you create the icon:

    Application.Run()
    

    Note that this method will not return, so you can't do anything after calling it. This means that you'll have to do all your other work in a separate thread.

    What happens is that the OS sends your application a message telling it that the tray icon has been right-clicked, but the tray icon code never sees it (because these messages are processed by Application.Run) and so can't respond by opening the menu.

提交回复
热议问题