|
阅读:1885回复:3
TOC中怎么知道点击的是那个label还是符号
<P>如下函数是判断点击到的类型的代码:<BR>Private Sub TOCControl1_OnMouseUp(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)<BR> Set m_pLayer = Nothing</P>
<P> Dim sLayerIsNothing As String<BR> Dim pObj As IUnknown<BR> Dim pData As Variant<BR> Dim pItem As esriTOCControlItem<BR> Call TOCControl1.HitTest(x, y, pItem, m_pBasicMap, m_pLayer, pObj, pData)</P> <P> Dim sLegendGroupInfor As String<BR> '获取 LegendGroup 的信息<BR> sLegendGroupInfor = GetLegendGroupInfor(pObj)</P> <P> If m_pLayer Is Nothing Then<BR> sLayerIsNothing = vbCrLf ; "返回图层为 Nothing!"<BR> Else<BR> sLayerIsNothing = vbCrLf ; "返回图层名为:" ; m_pLayer.Name<BR> End If</P> <P> Dim sDataInfor As String<BR> '获取 TocControl.HitTest中 Data 参数的信息,表示选中的索引<BR> sDataInfor = GetDataInfor(pData)</P> <P> Select Case pItem<BR> Case esriTOCControlItemNone 'None<BR> MsgBox "未选定任何对象!" ; sLayerIsNothing ; vbCrLf ; sLegendGroupInfor ; vbCrLf ; sDataInfor<BR> Case esriTOCControlItemMap '选定了地图<BR> MsgBox "选定了地图!" ; sLayerIsNothing ; vbCrLf ; sLegendGroupInfor ; vbCrLf ; sDataInfor<BR> Case esriTOCControlItemLayer '选定了图层<BR> 'Call PopupMenu(mnuTOCOperator)<BR> MsgBox "选定了图层!" ; sLayerIsNothing ; vbCrLf ; sLegendGroupInfor ; vbCrLf ; sDataInfor<BR> Case esriTOCControlItemHeading '列头<BR> MsgBox "选定了列头!" ; sLayerIsNothing ; vbCrLf ; sLegendGroupInfor ; vbCrLf ; sDataInfor<BR> Case esriTOCControlItemLegendClass<BR> MsgBox "选定了图列!" ; sLayerIsNothing ; vbCrLf ; sLegendGroupInfor ; vbCrLf ; sDataInfor<BR> End Select<BR>End Sub</P> <P><BR>'获取 LegendGroup 的信息<BR>Private Function GetLegendGroupInfor(ByVal pLegendGroup As ILegendGroup) As String<BR> Dim pLegendClass As ILegendClass<BR> Dim i As Long<BR> <BR> If pLegendGroup Is Nothing Then<BR> GetLegendGroupInfor = "LegendGroup 对象为 Nothing!"<BR> Exit Function<BR> End If<BR> <BR> GetLegendGroupInfor = "LegendGroup 信息如下:"<BR> <BR> For i = 0 To pLegendGroup.ClassCount - 1<BR> Set pLegendClass = pLegendGroup.Class(i)<BR> GetLegendGroupInfor = GetLegendGroupInfor ; vbCrLf ; pLegendClass.Label<BR> Next i<BR>End Function</P> <P><BR>'获取 TocControl.HitTest中 Data 参数的信息,表示选中的索引<BR>Private Function GetDataInfor(ByVal pData As Variant) As String<BR> If IsEmpty(pData) Then<BR> GetDataInfor = "索引为 空值!"<BR> Else<BR> GetDataInfor = "索引为 " ; pData ; "!"<BR> End If<BR>End Function</P> |
|
|
1楼#
发布于:2007-02-26 22:28
<img src="images/post/smile/dvbbs/em02.gif" /><STRONG>精华</STRONG>感谢楼主<img src="images/post/smile/dvbbs/em06.gif" />
|
|
|
2楼#
发布于:2007-03-18 15:38
楼主辛苦<img src="images/post/smile/dvbbs/em02.gif" />
|
|
|
3楼#
发布于:2007-07-13 16:40
<P>谢谢楼主了,真好需要</P>
<P>非常感谢</P> |
|