mono/MonoGame — pull request #2856 by GhostTap (2014-07-27 21:09:48+00:00)
Title: WinForm Easy Embed

Hey @tomspilman,

It feels like creating an embedded Game class in win forms is extremely difficult in MonoGame. I've struggled with this for like 4 years now, and it seems that people on the web have hundreds of hacky work arounds to make this all work.

I was wondering if you would consider an addition like this which would greatly simplify making editors and other monogame embedded applications. Given the small changes, it makes it possible for me to do use a Custom User Control and have Monogame render to that instead of to the hard coded WinFormsGameForm. Controls will still work, mouse and everything. Sample code below.

```
private void Control_Load(object sender, EventArgs e)
{
if (this.DesignMode == false)
{
WindowsDeviceConfig.UseForm = false;
WindowsDeviceConfig.ControlToUse = this;

MyGame game = new MyGame();
game.IsFixedTimeStep = false;

Thread t = new Thread(new ThreadStart(() =>
{
while (true)
{
this.Invoke(new MethodInvoker(() =>
{
game.RunOneFrame();
}));

Thread.Sleep(16);
}
}));

t.IsBackground = true;
t.Name = "Monogame Thread";
t.Start();
}
}
```

Thoughts?