Drop event

G

geejay

I would like to handle the event where a shape is dropped (actually moved
would be better), in .NET.

Any ideas on how to do this?

I've checked the API and none of the events are drag events. I tried
handling the ShapeChanged event, but then I couldn't find out from the event
which shape had changed?

Cheers
 
A

AlEdlund

For shape moved you probably should be capturing the cell changed events
(making sure you filter), for shape 'dropped' you would typically test for a
shapeadded events. Here's some code for the shaped added,
al


Private Sub AxDrawingControl1_ShapeAdded(ByVal sender As Object, ByVal e As
AxMicrosoft.Office.Interop.VisOcx.EVisOcx_ShapeAddedEvent) Handles
AxDrawingControl1.ShapeAdded
Try

If e.shape Is Nothing Then Exit Sub
Dim vsoApp As Visio.Application = e.shape.Application


' if we are in a draw recordset get out
If vsoApp.IsInScope(pLngCurrScope) Then
Exit Sub
' Debug.Print("shaped added during draw recordset")
End If

If m_dictComponents.Count < 1 Then
' make sure we know where we are and set up the dictionaries
m_visPage =
Me.AxDrawingControl1.Window.Application.ActivePage
initPageDictionaries(m_visPage)
End If


Dim vsoShape As Visio.Shape = e.shape
Dim strMasterName As String = vsoShape.Master.Name


Dim intPos As Integer = 0

' if we find a master name with a period the fix it
intPos = InStr(strMasterName, ".")
If 0 < intPos Then
strMasterName = Mid(strMasterName, 1, intPos - 1)
End If

' IsInScope with visCmdObjectGroup parameter returns
' True if the shape is added using group action.

' Debug.Print(vsoApp.CurrentScope)

If vsoApp.IsInScope(visCmdObjectGroup) Then
Debug.Print("Shape added using grouping action. " _
& "Master name of the shape - " _
& strMasterName)

' is in scope with apply data graphic
ElseIf vsoApp.IsInScope(visCmdApplyDataGraphic) Then
Debug.Print("Shape Added using Apply Data Graphic")

' IsInScope with visCmdUFEditPaste parameter returns
' True if the shape is added using EditPaste action.
ElseIf vsoApp.IsInScope(visCmdUFEditPaste) Then
Debug.Print("Shape added using EditPaste action. " _
& "Master Name of the Shape - """ _
& strMasterName)

' IsInScope with visCmdEditPasteSpecial parameter
' returns True if the shape is added using
' EditPasteSpecial action.
ElseIf vsoApp.IsInScope(visCmdEditPasteSpecial) Then
Debug.Print("Shape added using EditPasteSpecial " _
& "action. Master name of the shape - " _
& strMasterName)
Else

' build a new component class to work with



vsoShape.Application.ActiveWindow.DeselectAll()

End If ' test the scope of the operation


Catch com As COMException
Dim rethrow As Boolean = ExceptionPolicy.HandleException(com,
"Com+ Policy")
If (rethrow) Then
Throw
End If
Catch err As Exception
Dim rethrow As Boolean = ExceptionPolicy.HandleException(err,
"Log Only Policy")
If (rethrow) Then
Throw
End If
End Try


End Sub
 
D

David J Parker [MVP Visio]

Don't use CellChanged ... it will slow your code down
Use FormulaChanged instead.
 
J

John Goldsmith_Visio_MVP

Or if you're just looking for move notification then how about a User cell?
For example:

User.MoveMonitor = DEPENDSON(PinX,PinY)+CALLTHIS("ThisDocument.Moved")

(this would actually fire twice, once for PinX and once for PinY, but you
get the idea)

Best regards

John


John Goldsmith (Visio MVP)
www.visualSignals.typepad.co.uk
www.visualSignals.co.uk
 
G

geejay

Hi Al

Any ideas when I'm not dealing with an ActiveX control (I am developing an
Add-In).

Also, I would like to know when a shape has moved (e.g through a mouse
drag), not just when a master is dropped.

Cheers
 
A

AlEdlund

The calling process for an event is the same for an addin event as for an
activex control event. Both David and John have good input for approaching a
shape that moves. There are several examples of writing event handlers in
the Visio Sdk (including both generic events and formula changed handlers).
John's suggestion has the implication that you have to customize all of the
shapes you will use (either custom stencils, or alter them programmatically
when you drop them on the page).
hth,
al
 
G

geejay

Hi Al

Yes you are right. This was a case of RTFM :)

I am using the FormulaChanged event (following Davids idea) (although I
havent tested the speed of this yet).

FYI, I have implemented this as follows (not the full code):

private Visio.EPage_FormulaChangedEventHandler
page_FormulaChanged_EventHandler;

private void SetupUserEvents()
{
page_FormulaChanged_EventHandler =
new
Visio.EPage_FormulaChangedEventHandler(page_FormulaChanged);
this._visPage.FormulaChanged +=
page_FormulaChanged_EventHandler;
}


private void page_FormulaChanged(Visio.Cell cell)
{
if (!_alreadyProcessedForRelayout.Contains(cell.Shape.NameID))
{
if (cell.Name.Equals("PinX") || cell.Name.Equals("PinY"))
{
//stuff here
}
}
}
 

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