Home

Awesome

Banner

Welcome to MonoGame.Forms!

Wiki NuGet NuGet

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.

[!NOTE]

[!TIP]

[!IMPORTANT]

Setup MonoGame.Forms

Options:


Tutorials

Creating MonoGame.Forms Projects:

  1. Create a new WindowsForms project
  2. Install the nuget package
  3. Build the solution

Creating MonoGame.Forms Controls:

  1. Create a new class and name it DrawTest
  2. Inherit from MonoGame.Forms.Controls.MonoGameControl
  3. Override its Initialize(), Update() and Draw() method
  4. Save your solution
  5. 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

Tutorial

  1. Profit ???

Tutorial

Drawing

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 EditorService for this.

In the MonoGame.Forms.Control classes this service is called Editor. So, in order to draw something to the spriteBatch you need to do this:

Editor.spriteBatch.DrawString();

Let's take a look at the final DrawTest class:

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

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

        protected override void Initialize()
        {
        }
        
        protected override void Update(GameTime gameTime)
        {
        }

        protected override void 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.FontHeight / 2)),
                Color.White);

            Editor.spriteBatch.End();
        }
    }
}

Result:

Tutorial

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

Samples

Take a look at the MonoGame.Forms.Samples-Project, which is part of this repo, to learn more about how MonoGame.Forms works.


WTF is this InvalidationControl?

This specific control class doesn't need to override the Update() method, because it gets manually updated (by you!).

You simply need to call Invalidate() on a custom InvalidationControl for every change you want to see on it. After calling this, your control does not consume CPU power anymore. This is great when creating preview controls for textures and similar things!

Pics or It Didn't Happen

Here are some sample pics from the Blazor branch:

MonoGameControl InvalidationControl MultipleControls AdvancedInput

Projects using MonoGame.Forms

Rogue Engine Editor:

Rogue Engine Editor

Mercury Particle Sandbox:

Rogue Engine Editor

PenumbraPhysics.Editor:

YouTube Video


Now Have Fun with MonoGame.Forms!

Logo

Special Thanks