System Tray only (no dock icon) application using C# / Mono on Mac

后端 未结 2 2093
攒了一身酷
攒了一身酷 2020-12-06 01:01

I\'m looking to move one of my C# applications over to Mono for use on the Mac. Currently, I\'m trying to figure out how to make it a sort of \"background\" process, but sti

2条回答
  •  庸人自扰
    2020-12-06 01:33

    I have your answer:

    First, to add a Status bar icon (alternative of Notify Icon in Win Forms):

            NSStatusItem sItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30);
            sItem.Menu = notifyMenu;
            sItem.Image = NSImage.FromStream(System.IO.File.OpenRead(NSBundle.MainBundle.ResourcePath + @"/notify-icon.icns"));
            sItem.HighlightMode = true;
    

    notifyMenu is your instance of NSMenu as a means of context menu strip for your notify icon.

    and put your ICNS file made using Icon Composer in your project files and flag it as Content. (right click->build action->content)

    Now It is time to remove dock icon:

    on your info.plist file. make a new Boolean type item and name it "LSUIElement" and set the value to YES.

    Hope it helps. Regards, Peyman Mortazavi

提交回复
热议问题