Thursday, May 05, 2005

Hang graphics off the cursor

Sometimes in an application you want an element to track with the cursor for interactive placement. Here is a snippet, taken from one of our demo applications, that does just that.

...start snippet...

' Set new graphics so they are hung off the mouse for placement

Dim newCategoryId As Long
Dim newOffset As Long

newCategoryId = GTVX1.GetLastDrawnCategoryId
newOffset = GTVX1.GetLastDrawnOffset

If GTVX1.SelectElement(newCategoryId, newOffset) Then ' newly placed graphics

GTVX1.ActivateSelectedElementMove ' activate selected element move mode
GTVX1.RefreshView

End If

...end snippet...

In case your app is not with GTVx, but is an external app for GTViewer, just change the "GTVX1" part to "docObj" for the two lines that get the new categoryId and offset, and change "GTVX1" to "viewObj" for the three lines in the "If" paragraph.

Happy app dev!

No comments: