Setting Window Position - old tutorial is broken

The tutorial for setting window position doesn’t work anymore, because the OpenTKGameWindow class has either been changed to be internal Is there any way to work around this, or are there any newer/better ways of moving the window?

I believe the first chunk of code in there will work under MonoGame DirectX:

System.Windows.Forms.Form form = (System.Windows.Forms.Form)System.Windows.Forms.Control.FromHandle(window.Handle);
form.Location = new System.Drawing.Point(x, y);

It looks like the Handle in MonoGameGL is now for a UserControl (GLControl)
https://github.com/opentk/opentk/blob/develop/Source/GLControl/GLControl.cs

Looks like you might be able to do:

System.Windows.Forms.Form form = System.Windows.Forms.Control.FromHandle(window.Handle).ParentForm;
form.Location = new System.Drawing.Point(x, y);

At a guess :slight_smile:

I think you mean “FindForm()” since there’s no such creature as ParentForm. :wink:

But, hmm. “Control.FromHandle(Window.Handle)” returns null, which would seem to suggest that Window.Handle doesn’t actually point to a WinForms control. At first I thought it was because MonoGame runs on “Any CPU” and I had my game set to x86, but it doesn’t work with my game and libraries set to Any CPU, either. Looking at the source code seems to suggest that it’s some kind of OpenTK thing, but I have no idea how to narrow it down from there.

If you post an issue on the monogame github you could @thefiddler and they might be able to help (they maintain opentk)