I'm looking for some help figuring out the current position of the Monogame windowed form. My ultimate goal is to figure out when the user is clicking inside of the game window and where they're clicking.
Getting the mouse position is easy:
var mouseState = OpenTK.Input.Mouse.GetState();
var mousePosition = new Point(mouseState.X, mouseState.Y);
That returns a Point relative to the computer's display. I'm running my app as a windowed form, so I need to compute the mouse position inside of the window based off the forms current location on the monitor.
And in reading up on the subject, it looks like this should give me the point data I need:
System.Windows.Forms.Form form = (System.Windows.Forms.Form)System.Windows.Forms.Control.FromHandle(this.Window.Handle);
var formPosition = new Point(form.Location.X, form.Location.Y);
Trouble is, that the object form is always coming back as a null object. this.Window.Handle will return a valid (System.IntPtr) handle ID, but the form object is never created.
While I'm stopped at a break point, I can see the data I need inside the this.Window located at ((OpenTK.NativeWindow)(((Microsoft.Xna.Framework.OpenTKGameWindow)(this.Window)).window)).Location - but that location is a non-public location so I can't get it out of there.
Any suggestions?
Mouse
API do this already? \$\endgroup\$