C# XNA - 获取当前屏幕分辨率

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8954945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 05:22:13  来源:igfitidea点击:

XNA - Get Current Screen Resolution

c#xnascreendesktopresolution

提问by Jpin

Is it possible to get the current desktop screen resolution?

是否可以获得当前的桌面屏幕分辨率?

I have a few minor settings in my XNA game one of which is screen resolution. What I want to do is blank out a screen resolution option if it is larger than the current desktop resolution supports.

我的 XNA 游戏中有一些小设置,其中之一是屏幕分辨率。如果屏幕分辨率选项大于当前桌面分辨率支持,我想要做的是将其清除。

采纳答案by Nic Foster

GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Widthand .Heightwill give you the device's current resolution.

GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width并且.Height会给你设备的当前分辨率。

Game.GraphicsDevice.Viewporthas height and width variables you can query, that will give you the resolution of your viewport. The viewport is usually the size of the window, but that's not guaranteed.

Game.GraphicsDevice.Viewport具有您可以查询的高度和宽度变量,这将为您提供视口的分辨率。视口通常是窗口的大小,但这并不能保证。

Window.ClientBounds.Widthand .Heightwill give you the resolution of your game window.

Window.ClientBounds.Width并将.Height为您提供游戏窗口的分辨率。

回答by Justin Self

GraphicsAdapter.SupportedDisplayModeswill return a collection of all of the supported aspect ratios. You can then show all of the ratios that are in this collection.

GraphicsAdapter.SupportedDisplayModes将返回所有支持的纵横比的集合。然后,您可以显示此集合中的所有比率。