MonoGame增加系统托盘功能
在某些时候需要给游戏增加系统托盘功能,方法如下:
1.添加System.Windows.Forms.dll引用
2.在Game类的Initialize()方法中增加如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
NotifyIcon notifyIcon = new NotifyIcon(); notifyIcon.Title = "游戏名"; notifyIcon.Icon = new System.Drawing.Icon(TitleContainer.OpenStream("white.ico")); notifyIcon.Visible = true; System.Windows.Forms.MenuItem notifyMenuClose = new System.Windows.Forms.MenuItem("Exit"); notifyMenuClose.Click += (ss, ee) => { }; System.Windows.Forms.MenuItem[] notifyMenuList = new System.Windows.Forms.MenuItem[] { notifyMenuClose }; notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(notifyMenuList); |
这里用到TitleContainer,需要添加名称空间Microsoft.Xna.Framework; white.ico改成Content
如果您对C#游戏开发感兴趣,可以扫下面二维码加入我们的QQ群来一起学习交流
原创文章,转载请注明本文链接地址(违者必究):MonoGame增加系统托盘功能