我正在將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
並告訴它渲染表面是另一個控件的表面?