ITOCControl-HitTest メソッドの使用例

'ITOCControl::HitTestメソッド サンプル
'ITOCControl::HitTestメソッドによるデータフレーム,レイヤ,凡例オブジェクトの取得方法
Private Sub TOCControl1_OnMouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)
    
    'TOCControlの取得
    Dim pTOCControl As ITOCControl
    Dim pItem As esriTOCControlItem
    Dim pMap As IMap                    'データフレーム
    Dim pLayer As ILayer                'レイヤ
    Dim pLegendGroup As ILegendGroup    'シンボル
    Dim pIndex As Variant               'シンボルに応じた引数
    
    'HitTest
    Set pTOCControl = TOCControl1.object
    pTOCControl.HitTest x, y, pItem, pMap, pLayer, pLegendGroup, pIndex
    
    'オブジェクトが取得できない場合
    If pItem = esriTOCControlItemLegendClass Then
        '個々のシンボルを取得
        Dim pLegendClass As ILegendClass
        Set pLegendClass = pLegendGroup.Class(pIndex)
            
        Dim pSymbol As ISymbol
        Set pSymbol = pLegendClass.Symbol
        
        Dim pSimpleFillSymbol As ISimpleFillSymbol
        
        'ポリゴンシンボルの場合シンボル色を変更
        If TypeOf pSymbol Is ISimpleFillSymbol Then
        
            MsgBox "SimplePolygonSymbol"
            
            'ポリゴン色を赤に変更
            Set pSimpleFillSymbol = pSymbol
            Dim pRgbColor As IRgbColor
            Set pRgbColor = New RgbColor
            
            pRgbColor.RGB = vbRed
            pSimpleFillSymbol.Color = pRgbColor
        End If
        
        'ラスタのカラーランプシンボル
        If TypeOf pSymbol Is IColorRampSymbol Then MsgBox "ColorRampSymbol " & pIndex
        
        'ラスタの個別カラー
        If TypeOf pSymbol Is IColorSymbol Then MsgBox "ColorSymbol " & pIndex
    End If

    
    'TOCの再描画
    pTOCControl.Update
        
End Sub