2012-10-15 21 views
4

我正在將XNA轉換爲MonoGame的Gleed2D如何在MonoGame中獲得底層窗口?

Gleed2D是一個Windows窗體應用程序,它實例化XnaGame。然後隱藏由Game創建的window,並將DeviceWindowHandle設置爲主窗體上的Canvas

我知道這是一口一口;該代碼自己說明:here it is in full
相關的位是在構造函數中:

  _drawSurface = mainForm.GetHandleToCanvas(); 
      _graphics = new GraphicsDeviceManager(this) 
      { 
       PreferredBackBufferWidth = 800, 
       PreferredBackBufferHeight = 600 
      } ; 

     _graphics.PreparingDeviceSettings += graphics_PreparingDeviceSettings; 

     _winform = (Form)Form.FromHandle(Window.Handle); 

     _winform.VisibleChanged += game1VisibleChanged; 
     _winform.Size = new Size(10, 10); 

     Mouse.WindowHandle = _drawSurface; 

     Size pictureBoxSize = _mainForm.CanvasSize ; 

     ResizeBackBuffer(pictureBoxSize.Width, pictureBoxSize.Height) ; 

        ... some other stuff.... 


    void graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e) 
    { 
     e.GraphicsDeviceInformation.PresentationParameters.DeviceWindowHandle = _drawSurface; 
    } 

我的問題是:在XNA中,Window.Handle可以轉換爲Form。在MonoGame中,它實現爲OpenTK.GameWindow如何才能到達實際的窗口,以便我可以隱藏和/或調整它的大小?。另一個問題是:如何創建一個MonoGame Game並告訴它渲染表面是另一個控件的表面?

回答

1

不知道這是否有幫助,但在MonoGame遊戲構造函數中,它將GraphicsDeviceManager初始化爲一個名爲_graphics的變量。你可以從哪個對象中獲得當前的GraphicsDevice Manager,它有一個名爲SetRenderTarget和SetRenderTargets的方法。 YOu也可以通過this.Window.Handle獲得Handle到遊戲窗口,其中「this」是當前的遊戲對象。圖形設備中還有一個Present方法,您可以傳遞源和目標Rectangle以及任何Windows句柄。 祝你好運。