Setting a form icon for an XNA window?

Is there a way to change the XNA game form icon (i.e. the one that appears in the upper left corner of the form and on the taskbar)?

I currently have a multi-icon with various sizes, including 16x16. Unfortunately, the project property "Application → Resources → Icon and Manifest" uses 32x32 and scales it, not its own.

I would like to manually set the icon to use the 16x16 contained in the icon that I have and, if possible, dynamically change it at runtime.

Thanks.

+3
source share
1 answer

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 , .

:

  • System.Windows.Forms
  • System.Drawing

Game.ico , .

+2

Source: https://habr.com/ru/post/1724437/


All Articles