Alright this might be old as hell, but I was having trouble with this and I found an answer.
The example project provided by Microsoft (XNA WinForms Sample 1) includes three main classes that you need in order to MAKE a control.
- GraphicsDeviceControl.cs
- GraphicsDeviceService.cs
- ServiceContainer.cs
Starting with a fresh windows form project you will need to make references to Microsoft.Xna.Framework and Microsoft.Xna.Framework.Graphics. Now make a reference to your XNA project where your XNA game is located (or game library).
Copy over those three files and change the namespace on those three classes to your windows form namespace. Then you will want to make a NEW class which inherits from GraphicsDeviceControl.
Now modify the using statements to include the XNA libraries you need. Then add the overrides for Initialize, Dispose, Draw, and any other methods you will be needing to modify.
e.g.
#region Using Statements
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
#endregion
namespace WindowsFormsApplication1
{
public class MapControl : GraphicsDeviceControl
{
protected override void Initialize()
{
//throw new System.NotImplementedException();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
protected override void Draw()
{
//throw new System.NotImplementedException();
}
}
}
Now compile the windows form project and your new control will appear in the toolbox.
This all came about because I couldn't figure out why I kept getting errors when trying to place the abstract base class GraphicsDeviceControl on the form, but it's taken me 2 years to actually figure out why.