Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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!

share|improve this question
1  
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. –  Andrew Russell Aug 1 '12 at 7:48
    
@AndrewRussell Seems your link is kinda "dead" now. Any way to still get to the original article on MSDN? –  Uwe Keim Aug 27 '13 at 14:01
1  
To answer my own question, this is the correct link now. –  Uwe Keim Aug 27 '13 at 14:04
add comment

2 Answers

up vote 2 down vote accepted

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>( );
}
share|improve this answer
    
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. –  XtremeCheese Aug 1 '12 at 0:38
    
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 –  Darcara Aug 1 '12 at 0:44
    
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. –  XtremeCheese Aug 1 '12 at 0:59
    
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. –  Darcara Aug 1 '12 at 1:28
    
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! –  XtremeCheese Aug 1 '12 at 1:42
show 10 more comments

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!

http://create.msdn.com/en-US/education/catalog/sample/winforms_series_1

share|improve this answer
    
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. –  Darcara Aug 1 '12 at 17:20
    
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.) –  Vaughan Hilts Aug 1 '12 at 18:06
    
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 :)) –  Darcara Aug 1 '12 at 18:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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