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

拟墨画扇 提交于 2019-11-27 22:12:39

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

I do not know whether I understand your question properly. If you just need an application without any notion of main window, but with system tray, I once did it with WinForms using code like

static void Main()
{
    Application.Run(new MyContext());
}

Where MyContext was a class derived from ApplicationContext which in its constructor created a tray icon using NotifyIcon class. In fact Application.Run() starts message loop for your application giving tray icon a chance to answer user clicks (tray icon itself could be created earlier). It worked on Windows and Ubuntu, never tested on Mac.

Nevertheless today I would use Gtk# on Linux and MonoMac on Mac. In the first case concept is probably very similar (you can also see Tomboy code, it does exactly that!). In the second - don't know, never used it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!