在某些时候需要给游戏增加系统托盘功能,方法如下:

1.添加System.Windows.Forms.dll引用

image

2.在Game类的Initialize()方法中增加如下代码:

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