I’ve embedded Monogame into a Windows Form using this code:
private IntPtr drawSurface;
private Control gameForm;
public Game(MainWindow window)
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
this.drawSurface = window.pcbViewport.Handle;
graphics.PreparingDeviceSettings += new EventHandler<PreparingDeviceSettingsEventArgs>(graphics_PreparingDeviceSettings);
Mouse.WindowHandle = drawSurface;
gameForm = Control.FromHandle(this.Window.Handle);
gameForm.VisibleChanged += new EventHandler(gameForm_VisibleChanged);
}
private void gameForm_VisibleChanged(object sender, EventArgs e)
{
if (gameForm.Visible)
{
gameForm.Visible = false;
}
}
private void graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
{
e.GraphicsDeviceInformation.PresentationParameters.DeviceWindowHandle = drawSurface;
}
Now, this code used to work… I think. It’s been a while and the code is on another computer with an older version so I seem to remember this working before now with Monogame. Anyway, the problem is that Mouse input doesn’t work! Keyboard and Gamepad input work fine, but Mouse input doesn’t register at all. I’ve experimented and found that if I take out the VisibleChanged event, it works but it also shows the GameWindow as well as the form (which it doesn’t need to as it’s being drawn in the PictureBox.
I’m aware that I can put the GameWindow in a Control, and if need be then I’ll do that but I’m trying to see if there is a solution to making the existing code work again.