Welcome to MSDN Blogs Sign in | Join | Help

Using XNA with WinForms

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!

Published Tuesday, January 23, 2007 3:50 PM by ShawnHargreaves

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Monday, February 05, 2007 8:49 AM by dorvo

# re: Using XNA with WinForms

If we wanted to do away with the Game class for building, say, a small game engine that'll work on the 360, what would we pass for the handle to the window?

Monday, February 05, 2007 9:58 AM by ShawnHargreaves

# re: Using XNA with WinForms

It doesn't matter. Xbox has no WinForms, and no window handles, so that parameter is ignored.

Sunday, March 04, 2007 6:09 PM by zygote

# Using XNA with WinForms

I have created a tutorial with example that will run XNA inside a Windows.Form (complete with resizing, etc).

It uses very few lines of code and is in english ;)

http://www.ziggyware.com/readarticle.php?article_id=82

Monday, October 26, 2009 12:57 PM by ibrahim dogan

# re: Using XNA with WinForms

Shawn, I can't understand why you people underestimate the importance of some developers wanting to use XNA in winforms. Not everyone is a game developer and need a full screen 3D environment. I , for one, develop an interior design application for windows desktop. So I need 3D in my app, I dont want to use C++ and directx, as it is not an option compared to C# and xna. Please take people like me seriously and provide more samples of xna with winforms. I am an admirer of your blog and efforts. Turkey

Monday, October 26, 2009 1:09 PM by ShawnHargreaves

# re: Using XNA with WinForms

ibrahim: have you looked at the WinForms samples from creators.xna.com?

http://creators.xna.com/en-US/sample/winforms_series1

http://creators.xna.com/en-US/sample/winforms_series2

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker