Maximize window in XNA 4.0

你说的曾经没有我的故事 提交于 2020-01-05 03:35:43

问题


I am currently using the following code to allow the user to resize and maximize the window:

Window.AllowUserResizing = true; 
Window.ClientSizeChanged += Window_ClientSizeChanged; 

with the Window_ClientSizeChanged event handling the changes and re-scaling the drawn images etc.

This allows me to resize the window however much I want and also maximize it using the standard button in the window's handle. I would like to be able to start the application with the window in its maximized mode but can't figure out how to do so. I know I can use graphics.IsFullScreen = true; to show it in full screen mode but I would like to be able to run the program in a maximized, windowed mode. Any ideas?


回答1:


You can put this code in the constructor to do what you want:

Form form = (Form)Control.FromHandle(Window.Handle);
form.WindowState = FormWindowState.Maximized;

This requires that you add a reference to System.Windows.Forms to your project.

This does have the downside that it actually sets up the graphics device twice on startup. Once in the normal way, and then once again because the window was resized. (Although this all happens before the form is first displayed.)

It has the advantage of being extremely simple to implement.


I'm going to poke around for awhile and see if the initialisation order can be changed...

There really is no simple way to get around this problem, it would seem.



来源:https://stackoverflow.com/questions/18717084/maximize-window-in-xna-4-0

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