About the GraphicTracker with the map Sample
[C#]
SelectGT.cs
using System; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; using ESRI.ArcGIS.ADF.BaseClasses; using ESRI.ArcGIS.ADF.CATIDs; using System.Collections.Generic; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.EngineCore; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Carto; namespace GraphicTrackerMap { [Guid("2713c8ef-8c59-42c7-bbcd-a0a667b8f51b")] [ClassInterface(ClassInterfaceType.None)] [ProgId("GraphicTrackerMap.SelectGT")] public sealed class SelectGT : BaseTool { #region COM Registration Function(s) [ComRegisterFunction()] [ComVisible(false)] static void RegisterFunction(Type registerType) { // Required for ArcGIS Component Category Registrar support ArcGISCategoryRegistration(registerType); // // TODO: Add any COM registration code here // } [ComUnregisterFunction()] [ComVisible(false)] static void UnregisterFunction(Type registerType) { // Required for ArcGIS Component Category Registrar support ArcGISCategoryUnregistration(registerType); // // TODO: Add any COM unregistration code here // } #region ArcGIS Component Category Registrar generated code /// <summary> /// Required method for ArcGIS Component Category registration - /// Do not modify the contents of this method with the code editor. /// </summary> private static void ArcGISCategoryRegistration(Type registerType) { string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID); ControlsCommands.Register(regKey); } /// <summary> /// Required method for ArcGIS Component Category unregistration - /// Do not modify the contents of this method with the code editor. /// </summary> private static void ArcGISCategoryUnregistration(Type registerType) { string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID); ControlsCommands.Unregister(regKey); } #endregion #endregion private IHookHelper m_hookHelper; private GTMapForm m_form = null; public SelectGT() { base.m_category = "Graphic Tracker"; //localizable text base.m_caption = "Select GT"; //localizable text base.m_message = "Select GT"; //localizable text base.m_toolTip = "Select graphic"; //localizable text base.m_name = "GraphicTrackerMap_SelectGT"; //unique id, non-localizable (e.g. "MyCategory_MyTool") try { string bitmapResourceName = GetType().Name + ".bmp"; base.m_bitmap = new Bitmap(GetType(), bitmapResourceName); base.m_cursor = new System.Windows.Forms.Cursor(GetType(), GetType().Name + ".cur"); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap"); } } #region Overriden Class Methods public override void OnCreate(object hook) { if (m_hookHelper == null) m_hookHelper = new HookHelperClass(); m_hookHelper.Hook = hook; } public override void OnClick() { IToolbarControl2 toolBarControl = m_hookHelper.Hook as IToolbarControl2; IMapControl4 mapControl = m_hookHelper.Hook as IMapControl4; if (toolBarControl != null) mapControl = toolBarControl.Buddy as IMapControl4; if (mapControl == null) return; if (m_form == null) m_form = mapControl.CustomProperty as GTMapForm; } public override void OnMouseUp(int Button, int Shift, int X, int Y) { if (m_form.m_graphicTracker == null) return; // Iterate through the GraphicTracker and unselect them all m_form.m_graphicTracker.SuspendUpdate = true; foreach (int i in m_form.m_GTGeometries.Keys) m_form.m_graphicTracker.Highlight(i, false); m_form.m_graphicTracker.SuspendUpdate = false; //Highlight the graphic identified by the HitTest result int id = m_form.m_graphicTracker.HitTest(X, Y); if (id != -1) m_form.m_graphicTracker.Highlight(id, true); } #endregion } }
[Visual Basic .NET]
SelectGT.vb
Imports System.Drawing Imports System.Windows.Forms Imports System.Runtime.InteropServices Imports ESRI.ArcGIS.ADF.BaseClasses Imports ESRI.ArcGIS.ADF.CATIDs Imports System.Collections.Generic Imports ESRI.ArcGIS.Controls Imports ESRI.ArcGIS.EngineCore Imports ESRI.ArcGIS.esriSystem Imports ESRI.ArcGIS.Display Imports ESRI.ArcGIS.Geometry Imports ESRI.ArcGIS.Carto <Guid("2713c8ef-8c59-42c7-bbcd-a0a667b8f51b")> _ <ClassInterface(ClassInterfaceType.None)> _ <ProgId("GraphicTrackerMap.SelectGT")> _ Public NotInheritable Class SelectGT Inherits BaseTool #Region "COM Registration Function(s)" <ComRegisterFunction> _ <ComVisible(False)> _ Private Shared Sub RegisterFunction(registerType As Type) ' Required for ArcGIS Component Category Registrar support ArcGISCategoryRegistration(registerType) ' ' TODO: Add any COM registration code here ' End Sub <ComUnregisterFunction> _ <ComVisible(False)> _ Private Shared Sub UnregisterFunction(registerType As Type) ' Required for ArcGIS Component Category Registrar support ArcGISCategoryUnregistration(registerType) ' ' TODO: Add any COM unregistration code here ' End Sub #Region "ArcGIS Component Category Registrar generated code" ''' <summary> ''' Required method for ArcGIS Component Category registration - ''' Do not modify the contents of this method with the code editor. ''' </summary> Private Shared Sub ArcGISCategoryRegistration(registerType As Type) Dim regKey As String = String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID) ControlsCommands.Register(regKey) End Sub ''' <summary> ''' Required method for ArcGIS Component Category unregistration - ''' Do not modify the contents of this method with the code editor. ''' </summary> Private Shared Sub ArcGISCategoryUnregistration(registerType As Type) Dim regKey As String = String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID) ControlsCommands.Unregister(regKey) End Sub #End Region #End Region Private m_hookHelper As IHookHelper Private m_form As GTMapForm = Nothing Public Sub New() MyBase.m_category = "Graphic Tracker" 'localizable text MyBase.m_caption = "Select GT" 'localizable text MyBase.m_message = "Select GT" 'localizable text MyBase.m_toolTip = "Select graphic" 'localizable text MyBase.m_name = "GraphicTrackerMap_SelectGT" 'unique id, non-localizable (e.g. "MyCategory_MyTool") Try Dim bitmapResourceName As String = [GetType]().Name & ".bmp" MyBase.m_bitmap = New Bitmap([GetType](), bitmapResourceName) MyBase.m_cursor = New System.Windows.Forms.Cursor([GetType](), [GetType]().Name & ".cur") Catch ex As Exception System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap") End Try End Sub #Region "Overridden Class Methods" Public Overrides Sub OnCreate(ByVal hook As Object) If m_hookHelper Is Nothing Then m_hookHelper = New HookHelperClass() End If m_hookHelper.Hook = hook End Sub Public Overrides Sub OnClick() Dim toolBarControl As IToolbarControl2 = TryCast(m_hookHelper.Hook, IToolbarControl2) Dim mapControl As IMapControl4 = TryCast(m_hookHelper.Hook, IMapControl4) If toolBarControl IsNot Nothing Then mapControl = TryCast(toolBarControl.Buddy, IMapControl4) End If If mapControl Is Nothing Then Return End If If m_form Is Nothing Then m_form = TryCast(mapControl.CustomProperty, GTMapForm) End If End Sub Public Overrides Sub OnMouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Integer, ByVal Y As Integer) If m_form.m_graphicTracker Is Nothing Then Return End If ' Iterate through the GraphicTracker and unselect them all m_form.m_graphicTracker.SuspendUpdate = True For Each i As Integer In m_form.m_GTGeometries.Keys m_form.m_graphicTracker.Highlight(i, False) Next m_form.m_graphicTracker.SuspendUpdate = False 'Highlight the graphic identified by the HitTest result Dim id As Integer = m_form.m_graphicTracker.HitTest(X, Y) If id <> -1 Then m_form.m_graphicTracker.Highlight(id, True) End If End Sub #End Region End Class