2012-08-02 129 views
2

這應該是一個非常簡單的問題,但經過大量搜索後,似乎沒有任何工作示例。 我只想讓我的XNA窗口從最大化開始。 我知道如何設置窗口的寬度和高度,但這不完全相同。 我也需要這樣做,而不是全屏。我只想要一個正常的最大化窗口。如何在XNA中最大化窗口

回答

4

@Cyral迄今爲止答案最接近,但它仍然不是你想要的。要最大化Windows窗體,請使用WindowState屬性:

var form = (Form)Form.FromHandle(Window.Handle); 
form.WindowState = FormWindowState.Maximized; 
+0

這看起來不錯,但是如何訪問XNA中的Form類?如果我嘗試引用它與System.Windows.Form它找不到。如果我嘗試在頂部添加「使用System.Windows」,它也找不到。 – Frobot 2012-08-03 17:07:47

+0

您需要在XNA項目中添加對「System.Windows.Forms.dll」程序集的引用,並且可能還需要'System.Drawing.dll'。 – 2012-08-03 17:13:30

+0

非常感謝我現在正在學習如何添加像這樣的引用,但它現在工作正常。 – Frobot 2012-08-03 18:04:09

5

將圖形設備管理器的IsFullScreen屬性設置爲true。

http://msdn.microsoft.com/en-us/library/bb195024(v=xnagamestudio.10).aspx

//from the above msdn sample 
    graphics = new GraphicsDeviceManager(this); 
    content = new ContentManager(Services); 

    graphics.PreferredBackBufferWidth = 800; 
    graphics.PreferredBackBufferHeight = 600; 
    graphics.PreferMultiSampling = false; 
    graphics.IsFullScreen = true; 

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphicsdevicemanager.isfullscreen(v=xnagamestudio.10).aspx

+2

你也可能需要調用'graphics.ApplyChanges();' – 2012-08-02 22:33:31

+0

@JohnMcDonald嗯,也許,我沒有這臺機器檢查XNA。 – asawyer 2012-08-02 22:35:01

+1

我可能應該提到我不想全屏。我仍然需要使最小化/最大化/關閉按鈕可見。 – Frobot 2012-08-02 22:40:46

0
_graphics = new GraphicsDeviceManager(this); 
DisplayMode displayMode = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode; 
this._graphics.PreferredBackBufferFormat = displayMode.Format; 
this._graphics.PreferredBackBufferWidth = (int)(displayMode.Width); 
this._graphics.PreferredBackBufferHeight = (int)(displayMode.Height); 

排序的對我的作品,但不大,你會明白,一旦你嘗試。我的意思是,這不是完美的,我相信有更好的方法,但對於原型設計這應該工作 - 或者也許有一些調整,你可以得到你需要的。

2

可以base.Initialize後

添加到System.Windows.Forms的和System.Drawing中的引用(但是,您將需要鍵入命名空間了,因爲含糊不清的)

使用下面的代碼

Form form = (Form)Form.FromHandle(Window.Handle); 
form.Location = Point(0, 0); 
form.Size = Screen.PrimaryScreen.WorkingArea.Size; 
0

其他已覆蓋自動最大化的步驟,而是讓實際的最大化按鈕,以便在需要的時候,用戶可以做到這一點,在遊戲中構造做到這一點:

Window.AllowUserResizing = true; 

根據您希望遊戲在調整大小開始和結束時的行爲方式,也許暫停遊戲,您可能需要處理其中一些事件。

Form form = (Form)Form.FromHandle(Window.Handle); 
    form.ResizeBegin += new EventHandler(form_ResizeBegin); 
    form.ResizeEnd += new EventHandler(form_ResizeEnd); 
    form.LocationChanged += new EventHandler(form_LocationChanged); 
相關問題