Issues with winforms. Alternatives?

I tried implementing this old tutorial but I keep getting an error from GLControl stating that the current platform (Windows 10) isn’t supported. I’m trying to build a map editor. Is there a fix for this? Is there another alternative out there? I’m sorry to beat this topic to death as I see it’s been discussed quite a bit over the years.

Hi !
You could use “any” gui library: emtpy keys, etc.
It should be ok for a “windows” like editor ala ue4 or unity

And Monogame will integrate with these?

There’s an issue on the GitHub page for simplifying the process of embedding MG like this. It’s easy for a DX project, but there is some stuff rhat needs to be done for OpenGL platforms.

How would I go about doing it on a DX project? The solutions by ArchaicOokami are just gone. Is there a DX class similar to OpenTK’s GLControl class that GraphicsDeviceControl can inherit from?
This tutorial should work. IIRC the only thing you need to change is a GraphicsDevice.Reset function call. You can just change this to the overload that MG does implement. There is a PR up to implement the overload used in the sample, but this will do the trick for now.

Once we refactor the OpenGL side so it works with this too, we can look at making it easier to embed MonoGame like this :slight_smile:

Thanks! I’ll give it a try and report back if I run into more issues.

1 Like

Alright, hit a couple of roadblocks.

  1. There was no overload for GraphicsDevice.Present() that took arguments so I removed those.

  2. There was no definition for GraphicsDevice.Reset() so I changed that to GraphicsDevice.Present() just to get it to build.

  3. The project built fine but when I tried to run it I got a “FileNotFoundException”. I’ll put the details of that at the end of the post

Is it possible that I’m not using the DirectX version of Monogame? Is that even a thing? Here’s the error output:

System.IO.FileNotFoundException was unhandled
FileName=System.Runtime, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
FusionLog==== Pre-bind state information ===
LOG: DisplayName = System.Runtime, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Appbase = file:///C:/Users/myxbo_000/documents/visual studio 2015/Projects/CTF_Game_My_Way/CTFGameEditor/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : MonoGame.Framework, Version=, Culture=neutral, PublicKeyToken=null.

LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\myxbo_000\documents\visual studio 2015\Projects\CTF_Game_My_Way\CTFGameEditor\bin\Debug\CTFGameEditor.vshost.exe.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: redirected to
LOG: Post-policy reference: System.Runtime, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///C:/Users/myxbo_000/documents/visual studio 2015/Projects/CTF_Game_My_Way/CTFGameEditor/bin/Debug/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Users/myxbo_000/documents/visual studio 2015/Projects/CTF_Game_My_Way/CTFGameEditor/bin/Debug/System.Runtime/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Users/myxbo_000/documents/visual studio 2015/Projects/CTF_Game_My_Way/CTFGameEditor/bin/Debug/System.Runtime.EXE.
LOG: Attempting download of new URL file:///C:/Users/myxbo_000/documents/visual studio 2015/Projects/CTF_Game_My_Way/CTFGameEditor/bin/Debug/System.Runtime/System.Runtime.EXE.

Message=Could not load file or assembly ‘System.Runtime, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The system cannot find the file specified.
at CTFGameEditor.GraphicsDeviceControl.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Oh, right. That should be fine like that.
For the Reset call without params you can probably pass in the current PresentationParameters of the graphicsdevice instead of using Present.

Did you start from a Winforms template? i recommend that you do. Looks like your issue is caused by assembly reference problems. I you start from WinForms template and add an MG reference that is probably easiest.
Edit: it might be the other way around :stuck_out_tongue: I’ll try this real quick

Yes, that’s a thing :stuck_out_tongue: If you use the OpenGL version you’ll get a NullReferenceException when initializing the GraphicsDevice

I got it working. Steps taken:

  1. Download the sample
  2. Open the project in VS (not the content project)
  3. Build the hudFont.spritefont with the pipeline tool.
  4. Build the project and place the hudFont.xnb in [projectOuptut]/Content/
  5. Delete the XNA references (Xna.Framework and Xna.Framework.Graphics) and add a reference to the MG DX dll or source project, whichever you prefer.
  6. Change the .Net framework target to 4.5 (this probably caused your issue)
  7. Change the Present call to use the parameterless overload, the other ones are not implemented in MG yet.
  8. Build and run

The sample should look like this:

But that’s currently failing because of the present overload I suppose. I have this on my TODO list :slight_smile:

Alright, so I tried opening the project in VS and got the error “The imported project “C:\Program Files (x86)\MSBuild\Microsoft\XNA Game Studio\Microsoft.Xna.GameStudio.targets” was not found. Confirm that the path in the declaration is correct, and that the file exists on disk”. I don’t have XNA Game Studio installed so this was expected. Do I just remove that line in the .csproj?

That probably won’t hurt

Alright, I couldn’t get the original project to build, so I started a new windows forms project and copied all the files from the old project in. I’m still getting the same FileNotFound Exception though this time it’s triggered by the line this.spinningTriangleControl = new WinFormsGraphicsDevice.SpinningTriangleControl();. I think I may just consider building a map editor directly in Monogame, or try and find some other solution. I really appreciate all the help.

I have an interest in this for stuff like map-making and customization too, so it would be nice if you post any findings :slight_smile:

The lack of the other Present overload also break resizing of WinForms controls.

And (the only working winforms control example which seemed to work, and I’ve searched a lot) seems to have disappeared

@KakCAT If you are looking for MonoGame render controls, which are placeable inside WindowsForms, you could try out my MonoGame.Forms project.

wow, I can’t believe I missed this one. The first time I saw it I thought it was a ui system for monogame and I just discarded it.

I’ll definitively be using this for new developments, I don’t know if I dare to use them for the already made tools though.