开发者

Setting the form icon for an XNA window?

Is there any way of changing the icon for an XNA 开发者_如何学Gogame form (i.e. the one that appears in the top left corner of the form, and on the taskbar)?

I currently have a multi-icon with a variety of sizes embedded, including a 16x16 one. Unfortunately the project property "Application -> Resources -> Icon and manifest" uses the 32x32 one and scales it down, rather than the native one.

I'd like to manually set the icon to use the 16x16 one contained in the icon I have, and if possible change it dynamically at run-time.

Thank you.


After reading this thread, I came up with the following code (from program.cs):

static void Main(string[] args)
{

    using (Game1 game = new Game1())
    {
            ((System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(game.Window.Handle)).Icon = new System.Drawing.Icon("file.ico");

            game.Run();
    }
}

file.ico should be copied to the same place as your executable.

You have to reference these assemblies in your solution:

  • System.Windows.Forms
  • System.Drawing

You can also replace the Game.ico in your solution folder, which has same effect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜