views:

32

answers:

2

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
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
+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
Ah, so that gives you a reference to the actual form… Good to know!
bcat
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
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
@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