I'm converting Gleed2D from XNA to MonoGame.
Gleed2D is a Windows Form application that instantiates an XnaGame
. The window
created by the Game
is then hidden and the DeviceWindowHandle
is set to that of a Canvas
on the main form.
I know that's a bit of a mouthful; the code speaks for itself: here it is in full.
The relevant bits are in the constructor:
_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;
}
My question is: In XNA, the Window.Handle
can be cast to a Form
. In MonoGame, it's implemented as an OpenTK.GameWindow
. How can I get to the actual window so that I can hide and/or resize it?. An alternative question would be: How can I create a MonoGame Game
and tell it the render surface is that of another control?
The GameWindow of OpenTK goes quite a long way, before a native Window is created. On this page you can see the native implementation: https://github.com/mono/opentk/blob/master/Source/OpenTK/Platform/Windows/WinGLNative.cs
My Solution would be to hack in the source code of OpenTK or ask in the OpenTK-Forums.
Not sure if this helps but in the MonoGame game constructor it initializes the GraphicsDeviceManager to a variable called _graphics. Which this object you can get the current GraphicsDevice Manager which has a method called SetRenderTarget and SetRenderTargets. YOu can also get the Handle to the game windows, by this.Window.Handle where "this" is the current game object. Also there is a Present method in the Graphics device that you can pass the source and destination Rectangle as well as any Windows Handle. Good Luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With