XNA 4.0 中的最大化窗口 [英] Maximize window in XNA 4.0

查看:25
本文介绍了XNA 4.0 中的最大化窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用以下代码来允许用户调整窗口大小和最大化:

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

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

使用 Window_ClientSizeChanged 事件处理更改并重新缩放绘制的图像等

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

这允许我随意调整窗口大小,并使用窗口句柄中的标准按钮将其最大化.我希望能够在窗口处于最大化模式的情况下启动应用程序,但不知道如何操作.我知道我可以使用 graphics.IsFullScreen = true; 以全屏模式显示它,但我希望能够以最大化的窗口模式运行该程序.有什么想法吗?

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?

推荐答案

你可以把这段代码放到构造函数中做你想做的事情:

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

这要求您向项目添加对 System.Windows.Forms 的引用.

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.

我去看看能不能改一下初始化顺序...

似乎没有简单的方法可以解决这个问题.

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

这篇关于XNA 4.0 中的最大化窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆