MonoGame.Forms 1.3.6527.622

MonoGame.Forms is the easiest way of integrating a MonoGame render window to your Windows Forms project. It should make your life much easier, when you want to create your own editor environment.

There is a newer version of this package available.
See the version list below for details.
Install-Package MonoGame.Forms -Version 1.3.6527.622
dotnet add package MonoGame.Forms --version 1.3.6527.622
paket add MonoGame.Forms --version 1.3.6527.622
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Welcome to MonoGame.Forms!

MonoGame.Forms is the easiest way of integrating a MonoGame render window into your Windows Forms project. It should make your life much easier, when you want to create your own editor environment.

Building

The following is required to successfully compile the solution:

  • MonoGame 3.6 (WindowsDX)
  • Visual Studio 2015

How-To

Setup MonoGame.Forms

First you need to make your MonoGame.Forms library ready to use. This step is very easy; you just need to compile the PCL
from source and then just add the compiled DLL to your project.

This is the prefered route, when you want to make you own custom changes to the library or extend it.

Another option is to install the library with the NuGet package manager.

This is the prefered and easiest route to be automatically up to date.


Creating a simple DrawWindow

Let's start using the MonoGame.Forms library by creating a simple draw window!

(it's assumed that you already have created a new Windows Forms project with the installed library)

  1. Create a new class and name it DrawTest
  2. Inherit from MonoGame.Forms.Controls.DrawWindow
  3. Override the Initialize() method from DrawWindow
  4. Override the Draw() method from DrawWindow
  5. Save & Build your solution
  6. Double Click on Form1.cs so that the Designer opens
  7. Open the Toolbox
  8. Drag & Drop the newly created control onto the Form1 control
  9. Open the Properties of the new control and set the Dock option to Fill
  10. Now run the solution and see the classical CornflowerBlue-Screen you are (surly) familiar with! ;-)

Now I bet you wonder how to draw something to this control, right? I bet you think that this is now the difficult part, right?
Well... it's not!

More than that it's basically the same like you are used to do in the MonoGame.Framework.
Just with a small difference (no it's still not difficult!)

In MonoGame you could draw someting to the screen with the SpriteBatch.
In MonoGame.Forms you will do the same but you need to use the DrawService for this.

In the DrawWindow class this service is called Editor. To draw something to the SpriteBatch you need to do this:

Editor.spriteBatch.DrawString();

Do you see? Easy! :)

To sum things up, let's take a look at the final DrawTest class:

using Microsoft.Xna.Framework;
using MonoGame.Forms.Controls;

namespace nugetTest
{
    public class DrawTest : DrawWindow
    {
        string WelcomeMessage = "Hello MonoGame.Forms!";

        protected override void Initialize()
        {
            base.Initialize();
        }

        protected override void Draw()
        {
            base.Draw();

            Editor.spriteBatch.Begin();

            Editor.spriteBatch.DrawString(Editor.Font, WelcomeMessage, new Vector2(
                (Editor.graphics.Viewport.Width / 2) - (Editor.Font.MeasureString(WelcomeMessage).X / 2),
                (Editor.graphics.Viewport.Height / 2) - (Editor.Font.MeasureString(WelcomeMessage).Y / 2)),
                Color.White);

            Editor.spriteBatch.End();
        }
    }
}

It's pretty much like in the MonoGame.Framework!


Now Have Fun with MonoGame.Forms!

Welcome to MonoGame.Forms!

MonoGame.Forms is the easiest way of integrating a MonoGame render window into your Windows Forms project. It should make your life much easier, when you want to create your own editor environment.

Building

The following is required to successfully compile the solution:

  • MonoGame 3.6 (WindowsDX)
  • Visual Studio 2015

How-To

Setup MonoGame.Forms

First you need to make your MonoGame.Forms library ready to use. This step is very easy; you just need to compile the PCL
from source and then just add the compiled DLL to your project.

This is the prefered route, when you want to make you own custom changes to the library or extend it.

Another option is to install the library with the NuGet package manager.

This is the prefered and easiest route to be automatically up to date.


Creating a simple DrawWindow

Let's start using the MonoGame.Forms library by creating a simple draw window!

(it's assumed that you already have created a new Windows Forms project with the installed library)

  1. Create a new class and name it DrawTest
  2. Inherit from MonoGame.Forms.Controls.DrawWindow
  3. Override the Initialize() method from DrawWindow
  4. Override the Draw() method from DrawWindow
  5. Save & Build your solution
  6. Double Click on Form1.cs so that the Designer opens
  7. Open the Toolbox
  8. Drag & Drop the newly created control onto the Form1 control
  9. Open the Properties of the new control and set the Dock option to Fill
  10. Now run the solution and see the classical CornflowerBlue-Screen you are (surly) familiar with! ;-)

Now I bet you wonder how to draw something to this control, right? I bet you think that this is now the difficult part, right?
Well... it's not!

More than that it's basically the same like you are used to do in the MonoGame.Framework.
Just with a small difference (no it's still not difficult!)

In MonoGame you could draw someting to the screen with the SpriteBatch.
In MonoGame.Forms you will do the same but you need to use the DrawService for this.

In the DrawWindow class this service is called Editor. To draw something to the SpriteBatch you need to do this:

Editor.spriteBatch.DrawString();

Do you see? Easy! :)

To sum things up, let's take a look at the final DrawTest class:

using Microsoft.Xna.Framework;
using MonoGame.Forms.Controls;

namespace nugetTest
{
    public class DrawTest : DrawWindow
    {
        string WelcomeMessage = "Hello MonoGame.Forms!";

        protected override void Initialize()
        {
            base.Initialize();
        }

        protected override void Draw()
        {
            base.Draw();

            Editor.spriteBatch.Begin();

            Editor.spriteBatch.DrawString(Editor.Font, WelcomeMessage, new Vector2(
                (Editor.graphics.Viewport.Width / 2) - (Editor.Font.MeasureString(WelcomeMessage).X / 2),
                (Editor.graphics.Viewport.Height / 2) - (Editor.Font.MeasureString(WelcomeMessage).Y / 2)),
                Color.White);

            Editor.spriteBatch.End();
        }
    }
}

It's pretty much like in the MonoGame.Framework!


Now Have Fun with MonoGame.Forms!

Release Notes

Reorganized the test project and rethought the control creation process. Now the user don't inherit from the service classes, but they need to inherit directly from the control classes, so the corresponding ToolBox control item will automatically generated for him.

Version History

Version Downloads Last updated
1.6.7.1 464 5/17/2018
1.6.6.2 183 5/7/2018
1.6.6.1 182 5/3/2018
1.6.6 207 4/29/2018
1.6.5.3 164 4/28/2018
1.6.5.2 158 4/17/2018
1.6.5.1 177 4/10/2018
1.6.5 173 4/5/2018
1.6.4 254 2/21/2018
1.6.3 180 2/17/2018
1.6.2 390 2/14/2018
1.6.0.1 185 2/13/2018
1.6.0 203 2/12/2018
1.5.6552.3920 211 12/9/2017
1.5.7 196 1/3/2018
1.4.6531.20682 146 11/18/2017
1.3.6527.622 194 11/13/2017
1.2.6526.10308 134 11/13/2017
1.1.6526.9426 159 11/13/2017
1.0.6526.8638 134 11/13/2017
Show less