I'm trying to rig an XNA WinForms system so I can have a game editor, and I need to use the mouse for it. Since the XNA Mouse input class reports mouse position based off of the window's location, I need to place the form I have in the same spot. How can i get the location of the window that my XNA game uses?
+1
A:
The X
and Y
properties of the Game.Window.ClientBounds
struct should give you the absolute window coordinates you're looking for.
bcat
2010-08-24 00:31:07
That *almost* does it, but it gives me the position of the very upper left part of the window contents, not the actual window position. See my answer for how i did it.
RCIX
2010-08-24 00:51:39
+2
A:
I ended up doing it with this code:
Form gameWindowForm = (Form)Form.FromHandle(this.Window.Handle);
...
myForm.Location = new System.Drawing.Point(gameWindowForm.Location.X - 5,gameWindowForm.Location.Y - 5); //-5 pixels for adjustment
which works just dandy!
RCIX
2010-08-24 00:52:55
I actually got the first line from http://www.codeproject.com/KB/game/XNA_And_Beyond.aspx . Very helpful, though not complete, on how to get a windows forms setup to use XNA.
RCIX
2010-08-24 01:04:09
the -5 is going to change based on what window style is being used? So it won't work right in both classic styling, Xp styling, and vista/7 styling
McKay
2010-08-24 15:40:40
@McKay: true, but since i'm using it as an internal tool, that's not a problem. If anyone plans to use it to release a tool using this technique though, then you should do some sort of switch based on window type.
RCIX
2010-08-25 20:14:16