如何在MonoGame中获取底层窗口?

5

我正在将 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并告诉它渲染表面是另一个控件的表面?
2个回答

1

不确定这是否有帮助,但在MonoGame游戏构造函数中,它将GraphicsDeviceManager初始化为名为_graphics的变量。通过此对象,您可以获取当前的GraphicsDevice Manager,其中有一个名为SetRenderTarget和SetRenderTargets的方法。您还可以通过this.Window.Handle获取游戏窗口的句柄,其中“this”是当前游戏对象。此外,Graphics device中还有一个Present方法,您可以传递源矩形、目标矩形以及任何Windows Handle。


1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接