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

隐身守侯 提交于 2019-12-08 02:23:39

问题


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.


回答1:


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




回答2:


To update this question, for MonoGame 3.4 (maybe earlier) you can simply do

this.Window.Position = new Point(x, y);

No need to reflect into OpenTK stuff it seems




回答3:


In MonoGame: Tutorial: Setting window position in Xna/Monogame



来源:https://stackoverflow.com/questions/9726667/how-can-i-control-where-xna-positions-the-game-window-at-startup

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!