17

Is it possible to embed an XNA game in a C# WinForm or a C++ Window. If yes then How.

I want to use normal UI controls & have a windowed interface of the game for more interactive & dynamic simulations.

Moon
  • 19,518
  • 56
  • 138
  • 200
  • 3
    the Googled results were complicated and the those results didn't led to what Andrew mentioned below – Moon Jul 02 '11 at 19:10

2 Answers2

21

The official samples:

Darren Reid
  • 2,322
  • 20
  • 25
Andrew Russell
  • 26,924
  • 7
  • 58
  • 104
  • yes.. i would go for this as well as it is official from Microsoft as well – Moon Jul 02 '11 at 18:13
  • SIDE NOTE: Neither addresses the issue of Mouse input interaction with the scene. –  Aug 19 '13 at 04:35
  • 1
    I've answered your question [here](http://stackoverflow.com/a/18381796/165500). Basically you must set `Mouse.WindowHandle` correctly (or use WinForms events). – Andrew Russell Aug 22 '13 at 13:27
5

I've had success doing this using the method described here:

XNA 3.0 and Winforms, the easy way

The blog post was written for XNA 3.0, but I had no problems using the same method with XNA 4.0.

It's very simple compared to the official Microsoft sample, but as this method is not officially supported, you should use it at your own risk. It worked perfectly in my case, and it required only minimal changes to the Game class.

Lukas S.
  • 5,698
  • 5
  • 35
  • 50