我正在将Gleed2D从 XNA 转换为 MonoGame。
Gleed2D 是一个Windows 窗体应用程序,它实例化一个XnaGame
. 然后隐藏window
由创建的并在主窗体上设置为 a 。Game
DeviceWindowHandle
Canvas
我知道这有点拗口;代码不言自明:这里是完整的。
相关位在构造函数中:
_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
. 如何进入实际窗口以便隐藏和/或调整其大小?. 另一个问题是:我怎样才能创建一个 MonoGameGame
并告诉它渲染表面是另一个控件的表面?