monogame + windows forms

Hi!

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?

Thanks!
Kak

Check out this, it’s an year old, but it should still do the trick: http://jaquadro.com/2013/03/embedding-your-monogame-game-in-a-winforms-control/

Hi cra0zy,

thanks, that’s the web I used to get the tool working in the first time a few months ago :slight_smile: Unfortunately I’m no longer able to make it work.

I’m using XNA for the moment so it’s not urgent, but it’d probably be a good idea to get it working with monogame in the near future.

Thanks,
Kak

Which version of visual studio and which version of monogame are you using?

Hi cra0zy,

latest, coming from github.

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)

Thanks!
Kak

If you are using something similar to the official XNA sample
http://xbox.create.msdn.com/en-US/education/catalog/sample/winforms_series_1
it’s easy to convert it to monogame (DirectX platform).

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().

I don’t think that embedding tutorial works with visual studios 2013, ah well.

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.)

@Damien_James_Gibson
Did you ever Release the code? i am replying because i cant figure out how to message you

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.

Alternatively you may grab the sources from github - https://github.com/archaicookami

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.