I want to create various sprite tool and map editor using XNA. Now, the problem is I do not know how would I implement the window forms and components (such as button, check box, sprite list, etc.) into my program and allow it to completely control my XNA environment. If there is any tutorials or examples that show how to make editor for XNA, then I would be very pleasing.


  • \$\begingroup\$ Even though i always created my own editors, i mostly ended at that, with kind of complete editor and no energy for game :) So i would advise you to try use already created editors mapeditor.org and brashmonkey.com if you aim to complete game :) \$\endgroup\$ – Kikaimaru May 3 '12 at 17:16
  • \$\begingroup\$ If it's possible, can you tell me how you build the editor yourself? Do you integrate .NET framework with the XNA framework? I am just curious to know that, because I have never build one before. \$\endgroup\$ – user1542 May 4 '12 at 3:51

I have done several editors... and the easier is using c# winform... it provides you with buttons, panels, listbox...

Of course, you can integrate it in a panel, like proposes @milkboat, but I think that winform series is not a good example.. because the xna code part is not driven as usual, there is no game class, and the code becomes ugly...

I prefer use this code, http://pastebin.com/kkkmKm8n, is not mine, but I've modified it to add the interface and the CreateAndShow method.

This way your game will not suffer many modifications among using the editor or not using it.

You only have to inherit your game class from XnaControlGame, and the editor form that will host the xna control should implement IXnaFormContainer.

I think is easy and more elegant than other approachs.... because let you difference xna part from the winform part

An editor with this approach:


An editor with a simple form approach, when the form is visible is editor mode, when dissapears is game mode.


| improve this answer | |
  • \$\begingroup\$ I do wish people would stop using, posting and endorsing these awful hacks for XNA + WinForms. Please use the official sample. It is far better to write the simple code required to add what you need to the official sample, than it is to go around hacking together Game and Form. \$\endgroup\$ – Andrew Russell Aug 1 '12 at 7:57
  • \$\begingroup\$ my hack its not awful... :) lets the official sample use the Microsoft.Xna.Framework.Game class? NO.. my awful hack does and I can share components and code among editor and game... it is simpler... otherwise everyone is free of using it or not....;) \$\endgroup\$ – Blau Aug 1 '12 at 8:49
  • \$\begingroup\$ Yes it is awful. And it's especially annoying when other people see code like this (it's not just yours) promoted as being "right" and then run into problems with it. Game is an optional helper class in XNA! If you want functionality like it - please do it properly and implement your own class with Services, Content, Draw, Update, etc. It's not hard! Steal the internals from ExEn if you like. But don't try and bend XNA's Game class into doing something it is not designed to do! \$\endgroup\$ – Andrew Russell Aug 1 '12 at 12:13
  • \$\begingroup\$ xna itself it's not designed to work in a winform... so don't bother, using the winform sample or this is not so crucial... \$\endgroup\$ – Blau Aug 1 '12 at 13:26
  • \$\begingroup\$ The core XNA library (everything except microsoft.xna.framework.game.dll) is completely independent. All you need to provide is a PresentationParameters.DeviceWindowHandle that XNA (internally, DirectX) can use to create a graphics device. You can use anything that will give you a window handle - WinForms, Qt, wxWidgets. You could use Win32 if you wanted! The Game class provides a convenient default implementation. The WinForms sample provides another - it's open source and designed for the purpose. You are shoving a handle into Game's private constructor and hoping for the best! \$\endgroup\$ – Andrew Russell Aug 1 '12 at 13:51


This example from the XNA site shows you how to implement a xna device into a windows forms project.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.