仅系统托盘(无停靠图标)应用程序在 Mac 上使用

时间:2023-03-31
本文介绍了仅系统托盘(无停靠图标)应用程序在 Mac 上使用 C#/Mono的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将我的一个 C# 应用程序转移到 Mono 以在 Mac 上使用.目前,我正在尝试弄清楚如何使它成为一种后台"进程,但仍然能够拥有 GUI 元素(我相信这排除了 mono-service).p>

最终目标是这样的:

  1. 为大多数交互设置一个托盘图标.
  2. 删除启动应用程序通常附带的停靠图标
  3. 让应用程序在启动时运行.

简而言之,想想 Dropbox 应用程序的工作原理.我想要那种类型的 GUI,但要使用 Mono/Mac 应用程序.

我相信这通常是通过在应用程序包的 Info.plist 中设置 LSUIElement = 1 来完成的.但是,我没有运气.我认为这可能与从应用程序包中启动我的应用程序的 mono 命令有关.一旦应用程序启动 mono 我假设它不会级联到进一步的应用程序启动.不过,这纯粹是猜测.

有人对此有任何想法吗?谢谢.

解决方案

我有你的答案:

首先,添加一个状态栏图标(Win Forms中通知图标的替代品):

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

notifyMenu 是您的 NSMenu 实例,作为通知图标的上下文菜单条.

并将使用 Icon Composer 制作的 ICNS 文件放入您的项目文件中,并将其标记为内容.(右键->构建动作->内容)

现在是时候移除停靠图标了:

在您的 info.plist 文件中.创建一个新的 Boolean 类型项目并将其命名为LSUIElement"并将值设置为 YES.

希望有帮助.问候,佩曼·莫尔塔扎维

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 still have the ability to have GUI elements (I believe this rules out mono-service).

The ultimate goal is this:

  1. Put a tray icon up by the clock for the majority of interactions.
  2. Remove the dock icon that typically comes with a launched application
  3. Have the application run on startup.

In short, just think of how the Dropbox app works. I want that type of GUI, but with a Mono / Mac app.

I believe this is typically accomplished by setting LSUIElement = 1 in the application bundle's Info.plist. However, I've had no luck with it. I think it may have something to do with the mono command launching my application from within the app bundle. Once the app launches mono I'm assuming it doesn't cascade to further application launches. That is a pure guess, though.

Does anyone have any ideas on this? Thanks.

解决方案

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

这篇关于仅系统托盘(无停靠图标)应用程序在 Mac 上使用 C#/Mono的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:更改 WinForm 中标题栏的颜色 下一篇:在 C# 控制台应用程序上更改背景颜色

相关文章

最新文章