I'm looking to create my own level editor for a game I'm making, and I came across the following post:

Tutorial or Example of creating custom sprite tool/map editor for XNA?

In the example posted by Blau, I am unsure what needs to be replaced in this line, and with what:

XnaControlGame.CreateAndShow<MainDialog, VoxelEditorGame>( );

If anyone could help at all, that would be great!

  • 1
    \$\begingroup\$ I do wish people would stop using, posting and endorsing these awful hacks for XNA + WinForms. Please, please, please use the official WinForms sample code. \$\endgroup\$ – Andrew Russell Aug 1 '12 at 7:48
  • \$\begingroup\$ @AndrewRussell Seems your link is kinda "dead" now. Any way to still get to the original article on MSDN? \$\endgroup\$ – Uwe Keim Aug 27 '13 at 14:01
  • 1
    \$\begingroup\$ To answer my own question, this is the correct link now. \$\endgroup\$ – Uwe Keim Aug 27 '13 at 14:04

MainDialog is the type of your windows main form, that needs to implement IXnaFormContainer

//Form1 is the standard winform when a new WindowsForms application is created
public partial Form1 : Form, IXnaFormContainer{

//YourControl is some control placed on your form. I'm guessing a Panel will work
public Control XnaControl { get{return this.YourControl} }

//Game1 is your XNA game class
private XnaControlGame _game;
public XnaControlGame Game { get{return _game;} set{_game=value;} }

In the next step you need to alter your Game1 class

public class Game1 : XnaControlGame{  //instead of Microsoft.Xna.Framework.Game
  public Game1 ( IntPtr handle, System.Windows.Forms.Form parentForm, System.Windows.Forms.Control surfaceControl) : base(handle, parentForm, surfaceControl){

In the static void main

static void Main(string[] args){
  XnaControlGame.CreateAndShow<Form1, Game1>( );
  • \$\begingroup\$ Thank you! This clears things up a bit, but I'm still having some issues. When I go to run the code, I receive the following error: 'WindowsGame3.Form1' does not implement interface member 'WindowsGame3.IXnaFormContainer.Game' and this error: 'WindowsGame3.Form1' does not implement interface member 'WindowsGame3.IXnaFormContainer.XnaControl' I'm not exactly sure what to make of this. \$\endgroup\$ – XtremeCheese Aug 1 '12 at 0:38
  • \$\begingroup\$ It sounds like you are implementing the interface, but have not provided the two methods required like in the first code box. XnaControl and Game \$\endgroup\$ – Darcara Aug 1 '12 at 0:44
  • \$\begingroup\$ So XnaControl and Game need to be in the Form1.cs file correct? Also, what exactly am I returning with return this.YourControl? I apologize if this is something obvious, but I don't have much experience with WinForms at all at the moment. \$\endgroup\$ – XtremeCheese Aug 1 '12 at 0:59
  • \$\begingroup\$ XnaControl and Game are Properties of your Form, that is correct. With return this.YourControl you are returning the control that xna will render to. Make a Panel, name it YourControl and add it to the Form (via Designer or code). Don't forget to let your Game1 inherit from XnaControlGame. \$\endgroup\$ – Darcara Aug 1 '12 at 1:28
  • \$\begingroup\$ I'm getting closer here! My one and only error I have left now is: Error 1 'WindowsGame3.Form1' does not implement interface member 'WindowsGame3.IXnaFormContainer.Game'. 'WindowsGame3.Form1.Game' cannot implement an interface member because it is not public. Thank you again for all your help and patience! \$\endgroup\$ – XtremeCheese Aug 1 '12 at 1:42

This might not be what you want, but you're using an unofficial workaround to do this. I would honestly reccomend doing it the offical way with a UserControl, then you can even design inside the WinForms designer!


  • \$\begingroup\$ They seem to be doing the same, so I wouldn't call it a workaround. The msdn example is more straight forward and complete though. It would have to be changed to be able to accommodate the game class. \$\endgroup\$ – Darcara Aug 1 '12 at 17:20
  • \$\begingroup\$ It's definitely a workaround as it directly hacks the game into the control. There's no doubt you want to use the official sample on this one. (No knock on you, you answered his question.) \$\endgroup\$ – Vaughan Hilts Aug 1 '12 at 18:06
  • \$\begingroup\$ I only glossed briefly over the code, but the msdn example uses the handle of a (user defined) control to draw to it. The workaround sets the handle globally for the device, which in the end I assume does the exact same thing. I do however agree actually, since the msdn example is more complete as it handles lost devices, multiple controls and such (Don't worry :)) \$\endgroup\$ – Darcara Aug 1 '12 at 18:11

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.