我正在将 Gleed2D 从XNA转换为MonoGame。
Gleed2D是一个Windows窗体应用程序,实例化了一个XnaGame
。然后由Game
创建的window
被隐藏起来,将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
。我该如何访问实际的窗口以便隐藏和/或调整大小?另一个问题是:如何创建一个MonoGame Game
并告诉它渲染表面是另一个控件的表面?