tags:

views:

407

answers:

1

Is there any way of changing the icon for an XNA game 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.

A: 

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.

Sune Rievers