페이지

2012년 8월 30일 목요일

Visio SDK - Add Context Menu

To add user-defined features to the context menu, which is a menu shown when users click mouse right button, see the following code fragment.

Basically,
1. Define some variables


    ' Used in the marker event context string
    Public Const CONTEXT_BEGIN_MARKER As String = "/"
    Public Const CONTEXT_EVENT As String = "EVENT="
    Public Const CONTEXT_SOLUTION As String = "SOLUTION="
    Public Const SHAPE_RMA_CONNECTS_COMMAND_ID As Short = 100
    Public Const SHAPE_RMA_CONNECTS_COMMAND_ID_STR As String = "100"
    Public Const CONTEXT_SDK As String = "SDK"

    ' Caption of the right menu action item
    Public Const RMA_MENU_CAPTION As String = "&Add Attributes"

    ' Formula of the right menu action item
    Public Const RMA_MENU_FORMULA As String = "RUNADDONWARGS(""" & "QueueMarkerEvent"", """ & CONTEXT_BEGIN_MARKER & CONTEXT_EVENT & SHAPE_RMA_CONNECTS_COMMAND_ID_STR & CONTEXT_BEGIN_MARKER & CONTEXT_SOLUTION & CONTEXT_SDK & """)"


2. Attach following code to each shape

        ' It doesn't exist yet, so add the right menu
        ' action item.
        intActionRow = Shape.AddRow(Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionAction, Microsoft.Office.Interop.Visio.VisRowIndices.visRowLast, Microsoft.Office.Interop.Visio.VisRowIndices.visRowAction)

        ' Set the menu caption.
        vsoCell = Shape.CellsSRC(Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionAction, intActionRow, Microsoft.Office.Interop.Visio.VisCellIndices.visActionMenu)
        ' Set our caption string.
        strMenuCaption = StringToFormulaForString(RMA_MENU_CAPTION)
        vsoCell.FormulaU = strMenuCaption

        ' Set the action for the menu item.
        vsoCell = Shape.CellsSRC(Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionAction, intActionRow, Microsoft.Office.Interop.Visio.VisCellIndices.visActionAction)
        vsoCell.FormulaU = RMA_MENU_FORMULA

        ' Release all objects related to this copy of the master
        ' before calling close which will delete this copy.
        ' Failure to do this can cause an exception to be thrown.
        'UPGRADE_NOTE: Object vsoCell may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
        vsoCell = Nothing



3. Add codes to Application_MarkerEvent to catch a event from the context menu and to do something


    Private Sub Application_MarkerEvent(ByVal app As Microsoft.Office.Interop.Visio.Application, ByVal SequenceNum As Integer, ByVal ContextString As String) Handles Application.MarkerEvent

        If ContextString <> "" And ContextString.Contains("/cmd=DoubleClick") Then
            Msgbox( ContextString)
        End If
    End Sub



댓글 없음: