Making macros user-friendly : Providing user interaction for macros : 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 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.
|
Copyright 2013 Corel Corporation. All rights reserved.