Previous Document Next Document

Making macros user-friendly : Providing user interaction for macros : Capturing coordinates


Capturing coordinates

When capturing mouse actions, or when developing a complex macro solution, you may want to convert between screen coordinates and document coordinates. This conversion is done with the methods ScreenToDocument and DocumentToScreen of the Window class.

The following VBA example converts a set of screen coordinates into a point in the document that is visible in the active window:

Dim docX As Double, docY As Double
ActiveDocument.Unit = cdrMillimeter
ActiveWindow.ScreenToDocument 440, 500, docX, docY

The following VBA example returns the screen coordinates of a point in the document as it appears on the screen:

Dim screenX As Long, screenY As Long
ActiveDocument.Unit = cdrMillimeter
ActiveWindow.DocumentToScreen 40, 60, screenX, screenY

In both examples, the converted coordinates are returned in the last two parameters.

 
Screen coordinates start from the upper-left corner of the screen, so positive y-values are down the screen, whereas negative y-values are up the screen.

You can test whether a set of coordinates (that is, a point) is inside, outside, or on the outline of a curve by using the Shape.IsOnShape method. For a set of document coordinates, this method returns one of the following:

 
cdrInsideShape — if the coordinate is inside the shape
 
cdrOutsideShape — if the coordinate is outside the shape
 
cdrOnMarginOfShape — if the coordinate is on or near the outline of the shape

For example, the following VBA code tests where the point (4, 6) is in relation to the active shape:

Dim onShape As Long
ActiveDocument.Unit = cdrInch
onShape = ActiveShape.IsOnShape(4, 6)

Previous Document Next Document Back to Top

Copyright 2013 Corel Corporation. All rights reserved.