How to retrieve a Document window's coordinates

R

Rami

Gents,

I have a .net (2.0) C# Add-in that displays a windows form when a
button is clicked from Word XP.

I need the form to be positioned at the same (X, Y) coordinates as the
document window, that's the one that typically has the rulers on the
top and left sides, and vertical and horizontal scrollbars on the
opposite sides.

I was able to confirm that ActiveWindow.UsableWidth and
ActiveWindow.UsableHeight are the width and height of the Document
Window, I just need to find the (X, Y) coordinates of that window.

I thought the answer was in ActiveWindow.Left and ActiveWindow.Top but
it seems they always have the same values as Application.Left and
Application.Top.

Here's what the Word object model readily gives me:

Application.Top
Application.Left

ActiveWindow.Top
ActiveWindow.Left

Application.Height
Application.Width

ActiveWindow.Height
ActiveWindow.Width

Application.UsableHeight
Application.UsableWidth

ActiveWindow.UsableHeight
ActiveWindow.UsableWidth

I tried all combinations of these to get the (X, Y) coordinates of the
Document window to no avail. The closest I got was:

X = Application.Left + (Application.Width - ActiveWindow.UsableWidth)
Y = Application.Top + (Application.Height - ActiveWindow.UsableHeight)

The problem with these formulae is that they don't take into account
Toolbars added to the bottom and right sides of the Document window,
in which case the ActiveWindow's UsableWidth and UsableHeight are
affected but my X and Y coordinates shouldn't.

Any help would be appreciated.

Thank you in advance.
Rami.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top