这段代码可以让我们的视窗以当前的分辨率进行全屏切换。
1
private
void
ToggleFullScreen()
2 {
3 PresentationParameters presentation =
4 graphics.GraphicsDevice.PresentationParameters;
5 if (presentation.IsFullScreen)
6 {
7 graphics.PreferredBackBufferWidth = 800 ;
8 graphics.PreferredBackBufferHeight = 600 ;
9 Window.AllowUserResizing = false ;
10 }
11 else
12 {
13 GraphicsAdapter adapter = graphics.GraphicsDevice.CreationParameters.Adapter;
14 graphics.PreferredBackBufferWidth = adapter.CurrentDisplayMode.Width;
15 graphics.PreferredBackBufferHeight = adapter.CurrentDisplayMode.Height;
16 }
17 graphics.ToggleFullScreen();
2 {
3 PresentationParameters presentation =
4 graphics.GraphicsDevice.PresentationParameters;
5 if (presentation.IsFullScreen)
6 {
7 graphics.PreferredBackBufferWidth = 800 ;
8 graphics.PreferredBackBufferHeight = 600 ;
9 Window.AllowUserResizing = false ;
10 }
11 else
12 {
13 GraphicsAdapter adapter = graphics.GraphicsDevice.CreationParameters.Adapter;
14 graphics.PreferredBackBufferWidth = adapter.CurrentDisplayMode.Width;
15 graphics.PreferredBackBufferHeight = adapter.CurrentDisplayMode.Height;
16 }
17 graphics.ToggleFullScreen();
18 }