Previous Document Next Document

Making macros user-friendly : Providing user interaction for macros : Capturing mouse drags


Capturing mouse drags

To get the position of a mouse drag (or an area or rectangle), you can use the GetUserArea method of the Document class. This method pauses the macro until the specified period of time elapses, or until the user clicks, drags, and releases in the document or presses Escape. Here is a VBA example that uses the Document.GetUserArea method:

Dim doc As Document, retval As Long, shift As Long
Dim x1 As Double, y1 As Double, x2 As Double, y2 As Double
Set doc = ActiveDocument
doc.Unit = cdrCentimeter
retval = doc.GetUserArea(x1, y1, x2, y2, shift, 10, True, cdrCursorExtPick)
ActivePage.SelectShapesFromRectangle x1, y1, x2, y2, False

The following parameters for the Document.GetUserArea method are coded into the preceding example:

 
The variables x1 and y1 return the horizontal and vertical positions (respectively) of the upper-left corner of the area.
 
The variables x2 and y2 return the horizontal and vertical positions (respectively) of the lower-right corner of the area.
 
The parameter shift returns the combination of the Shift, Ctrl, and Alt keys that is held down by the user when dragging the mouse. The Shift, Ctrl, and Alt keys are assigned values of 1, 2, and 4 (respectively), the sum of which is the returned value.
 
The value 10 specifies the number of seconds for the user to click in the document.
 
The value True specifies that the SnapToObjects parameter is enabled.
 
The value cdrCursorExtPick specifies the icon to use for the cursor.

In the preceding example, the code ends by selecting the shapes that lie completely within the area by using the Page.SelectShapesFromRectangle method.

One of the following values is returned:

 
0 — The user successfully completes the selection.
 
1 — The user cancels by pressing Escape.
 
2 — The operation times out.

 
This method returns two points that are interpreted as the corners of a rectangle. However, the two points can also be used as the start point and end point of a mouse drag.
 
The returned coordinates are relative to the origin of the page and, unless explicity specified, are in document units.

Previous Document Next Document Back to Top

Copyright 2013 Corel Corporation. All rights reserved.