I’m trying to get an editor I did some time ago running again with the current MonoGame version but I’m unable to use it. I used jaquadro’s sample a long time ago but I’m having major problems getting it to work. I think the problem is that a Game instance is required in many places now in order to obtain the window, but there are lots of problems creating the Game object in Windows Forms (I’m not very skilled with WinForms also…)
Is there any MonoGame WinForms sample working with current codebase?
I just found this open pull request https://github.com/mono/MonoGame/pull/2856 which may lead into what I’m searching for. I’ll keep investigating (I hadn’t thought about looking at pull requests and issues)
Some Key points:
Create a SwapChainRenderTarget and initialize it with your winForm window.
In BeginDraw() set that SwapChainRenderTarget as your renderTarget.
In EndDraw() replace GraphicsDevice.Present(sourceRectangle, null, this.Handle) with GraphicsDevice.Present().
For anyone needing this in the future, Message me I will give you a .Control.dll I have made with fixes/optimization applied already. I’m releasing it Open Source on GitHub in the near future.
On my dll I have already applied the SwapChain nkast recommended in a way you dont have to manage the SwapChain at winForm level on your own its as simple to use as any other WinForms control. (Looking into geting OpenGL to work first if possible before releasing.)
Search Microsoft.Xna.Framework.Control on nuget for the version based on 3.4.
Search MonoGame.Framework…Control to get one based on 3.5. The 1.0 of the GL and DX versions(GL only works with one control, i cant fix that without modifying the MonoGame dll itself) are also based on the XNA control, however the latest versions of the above mentioned are modified to be a control you can set on screen and add event to for rendering and a property for the clearcolor.
Do note: For using the latest control source, you can set your own update method, or turn on the AutoDraw property (Which makes it update on Application.Idle) as well as the Draw process only calls the Clear before calling your draw event function, so theres no built in spriteBatch youd have to make an external one.