This should be simple... I am converting VBA customization to VB .NET in VS 2008 Express Edition. In VBA i have a custom selection tool. Aside from just selecting features, when OnMouseDown receives Button = 2 parameter (right click) I popup a context menu with some macro items that call various other procedures.
I need some help with making this work in .Net...
I used the ESRI .NET sample project to get the feel for this and i am sure i can re-create the select tool but i am having problems with the context menu. I would also like to know how to call procedures when user clicks the context menu item.
Private Sub UIToolControl1_MouseDown(ByVal button As Long, _
ByVal shift As Long, ByVal x As Long, ByVal y As Long)
Dim pLayer As ILayer
Dim pContextMenu As ICommandBar
Dim pAppPosition As IWindowPosition
Dim pPoint As POINTAPI
If pMxDoc.SelectedLayer Is Nothing Then
MsgBox "Select a layer in the TOC!": GoTo ep
End If
Select Case button
Case 1
Set pLayer = pMxDoc.SelectedLayer
If pLayer Is Nothing Then
MsgBox "You must select 1 feature layer in the TOC!": GoTo ep
End If
If Not TypeOf pLayer Is IGeoFeatureLayer Then
MsgBox "You must select 1 feature layer in the TOC!": GoTo ep
End If
Set m_pPoint = _
pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y)
m_bIsMouseDown = True
Case 2
'on right click = popup
Set pContextMenu = CommandBars.Create("Go2Grid", esriCmdBarTypeShortcutMenu)
Set pAppPosition = Application
' Add 3 built in commands to the new context menu using the
' built-in ArcID module.
pContextMenu.CreateMacroItem "New Feature Class", 8, _
"Normal.Module1.CreateNewFeatureClass"
pContextMenu.CreateMacroItem "Delete Layer", 13, _
"Normal.Module1.DeleteFeatureClass"
pContextMenu.CreateMacroItem "Copy To...", 20, _
"Normal.ThisDocument.CopyFeatures"
pContextMenu.CreateMacroItem "Draws Around...", 26, _
"Normal.ThisDocument.DrawsAroundFeatures"
pContextMenu.CreateMacroItem "Clear Tool", 10, _
"Normal.ThisDocument.ClearCurrentTool"
pContextMenu.CreateMacroItem "Delete Features", 13, _
"Normal.Module1.DeleteFeatures"
' Popup the menu.
pPoint.x = x
pPoint.y = y
ClientToScreen pActiveView.ScreenDisplay.hwnd, pPoint
pContextMenu.Popup pPoint.x, pPoint.y
Case Else
GoTo ep
End Select
End Sub