MS Visioでは、領域を表す図形があります。私は変更されるたびにエリアのテキストを更新するように自分の形をしたい。このために、DEPENDSONとともにコンテキストシェイプの "Shape is changed"という形でシェイプシートのQUEUEMARKER関数を使用しました。したがって、シェイプが変更されるたびに、VisioのイベントリストにMarkerEventが作成されます。 また、この "Shape is changed"イベントをリッスンするCOMアドインがあります。そのイベントがトリガーされると、変更されている図形の領域を更新する関数の1つを実行します。VB.NetでVisio MarkerEventイベントを聴く
Viser SDKのMarkerEventとAdd Adviseの例を見て、それをコピーしましたが、イベントを聞くことができません。何が間違っているのか理解してもらえますか?ここで
私はVisioのSDKから適応コードです:
Private WithEvents visioApplication As Microsoft.Office.Interop.Visio.Application
Private beginQueuedEvent As Integer
Private endQueuedEvent As Integer
Private betweenMarker As Boolean
Public Sub UseMarker(ByVal markedPage As Microsoft.Office.Interop.Visio.Page)
' Get the Application object of the currently running Visio application.
visioApplication = CType(markedPage.Application, Microsoft.Office.Interop.Visio.Application)
Try
betweenMarker = False
beginQueuedEvent = visioApplication.QueueMarkerEvent("Shape is changed")
Catch err As System.Runtime.InteropServices.COMException
System.Diagnostics.Debug.WriteLine(err.Message)
End Try
End Sub
Private Sub applicationMarkerEventHandler(ByVal theApplication As Microsoft.Office.Interop.Visio.Application, ByVal sequenceNumber As Integer, ByVal context As String) Handles visioApplication.MarkerEvent
Try
' Ignore marker events with no context string
If Not IsNothing(context) Then
If context.Length() <> 0 Then
' If the value of sequenceNumber is either beginQueuedEvent or
' endQueuedEvent, the event results from the calls to the
' QueueMarkerEvent method.
' Note: betweenMarker is used in the
' shapeAddedToPageEventHandler to process the ShapeAdded
' messages fired between the two QueueMarkerEvent calls.
If (sequenceNumber = beginQueuedEvent) Then
betweenMarker = True
End If
End If
End If
Catch err As System.Runtime.InteropServices.COMException
System.Diagnostics.Debug.WriteLine(err.Message)
End Try
End Sub
Private Sub shapeAddedToPageEventHandler(ByVal addedShape As Microsoft.Office.Interop.Visio.Shape) Handles visioApplication.CellChanged
Dim dA As Double 'Area value
Dim dP As Double 'Perimeter value
Dim sName As String 'Shape name
Dim xPS As Visio.Shape 'Visio Shape
Try
If (betweenMarker) Then
xPS = Application.ActiveWindow.Selection.PrimaryItem
If InStr(xPS.Name, ".") > 0 Then
sName = Left(xPS.Name, InStr(xPS.Name, ".") - 1)
Else
sName = xPS.Name
End If
Select Case sName
Case "My Area"
dA = xPS.AreaIU
dP = xPS.LengthIU
xPS.Cells("User.Area").FormulaForceU = dA
xPS.Cells("User.Perimeter").FormulaForceU = dP
End Select
End If
Catch err As System.Runtime.InteropServices.COMException
System.Diagnostics.Debug.WriteLine(err.Message)
End Try
End Sub