I want my form to start up and open in the center relative to window that was active when my form was called. Say if Firefox was active and I display the form, I'd like my form to be shown in the "center" of the firefox window.
I think one way I can achieve this is by using SetWindowPos from user32.dll, but I'm not too sure if there is an easier way.
I have already played around with SetWindowPos and found that I can easily center my window on the whole screen, but I'm not too sure about where I should start to work on centering it relative to another window.
Basically, I will need to:
- Grab window location/size
- Do the math to find the coordinates in center minus my form size to prep
- Show my form and use set window pos to position it correctly?
Note: CenterParent will not work for this, it seems to only work for another Form control. I want to use this with other windows, like Firefox for example.