Using XNA with WinForms

Originally posted to Shawn Hargreaves Blog on MSDN, Tuesday, January 23, 2007

I often see people trying to use the XNA Game class in unusual places, for instance to host an XNA game inside a WinForms application.

That is usually a bad idea.

The Game class is designed to be simple, automatically setting everything up ready for you to start coding. If you are doing something complicated and want more control over the details of how your window is created, this is only going to get in your way.

Just say no! If you want to render into a custom window, don't use the Game class. It will be much easier and more reliable to directly create your own GraphicsDevice object.

If you want to use the content pipeline, you will also need to implement a custom IGraphicsDeviceService and IServiceProvider, which the ContentManager uses to locate the GraphicsDevice instance.

Roger Boesch posted some code for doing exactly that. His page is in German, but if du sprichst nicht Deutsches, Google can translate. Make sure you look at his code from the original page, though, because Google gets rather confused when you ask it to translate C# from German into English!

Blog index   -   Back to my homepage