Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I control where XNA positions the game window at startup?

Tags:

c#

xna

I have the following annoyance: Whenever I start debugging an XNA game, the game window pops up in the center of my screen. Since I have a dual monitor system, I'd like to set the default startup position somewhere my second monitor. But, this should only happen in debug modus.

like image 729
Fabian Avatar asked Dec 13 '25 01:12

Fabian


1 Answers

You need to add a reference to System.Windows.Forms and System.Drawing(as pointed out by Steve H) and then do the following somewhere outside the constructor, like in the Initialize override.

var form = (System.Windows.Forms.Form)System.Windows.Forms.Control.FromHandle(this.Window.Handle);
form.Location = new System.Drawing.Point(0, 0);

The reason we have the whole namespace in the code is to avoid class name collisions(again, as pointed out by Steve H).

like image 116
William Avatar answered Dec 14 '25 17:12

William



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!