ArcObjects Library Reference

Use Custom Tool on Windows Form Snippet

Connect a tool embedded in a Windows Form with the ArcGIS Application Framework.

[C#]

///<summary>Connect a tool embedded in a Windows Form with the ArcGIS Application Framework.</summary>
/// 
///<param name="application">An IApplication interface.</param>
///<param name="uidValue">A System.String that is where your 'Application_Root_Namespace'  +  '.'  +  'Your_COM_Class_Tool'. The 'Application_Root_Namespace' is obtained in Visual Studio by clicking Project menu. Ex: "MyArcGISApplication.MyCustomTool"</param>
/// 
///<remarks>
///This snippet assumes you have a Windows Form that is launched as a result of a BaseCommand click in ArcGIS Desktop.
///See the walkthrough document ms-help://MS.VSCC.v80/MS.VSIPCC.v80/ESRI.EDNv9.2/NET_Desktop/01c01659-cdf8-4579-9c87-2b965e872d84.htm for an example of how to create and use a BaseCommand. 
///On the Windows Form you have a Windows Button, that when you click will execute the functionality of another custom COM Class that Inherits ESRI.ArcGIS.ADF.BaseClasses.BaseTool.
///This snippet would be inserted the Windows Form code behind file (.vb or .cs) and called as a result of the Windows Button click event.
///</remarks>
public void UseCustomToolOnWindowsForm(ESRI.ArcGIS.Framework.IApplication application, System.String uidValue)
{

  ESRI.ArcGIS.esriSystem.IUID UIDCls = new ESRI.ArcGIS.esriSystem.UIDClass();
  UIDCls.Value = uidValue;
  ESRI.ArcGIS.Framework.ICommandItem commandItem = application.Document.CommandBars.Find(UIDCls, false, false);

  if (commandItem == null)
  {
	return;
  }

  application.CurrentTool = commandItem;

}
[Visual Basic .NET]

'''<summary>Connect a tool embedded in a Windows Form with the ArcGIS Application Framework.</summary>
''' 
'''<param name="application">An IApplication interface.</param>
'''<param name="uidValue">A System.String that is where your 'Application_Root_Namespace'  +  '.'  +  'Your_COM_Class_Tool'. The 'Application_Root_Namespace' is obtained in Visual Studio by clicking Project menu. Ex: "MyArcGISApplication.MyCustomTool"</param>
''' 
'''<remarks>
'''This snippet assumes you have a Windows Form that is launched as a result of a BaseCommand click in ArcGIS Desktop.
'''See the walkthrough document ms-help://MS.VSCC.v80/MS.VSIPCC.v80/ESRI.EDNv9.2/NET_Desktop/01c01659-cdf8-4579-9c87-2b965e872d84.htm for an example of how to create and use a BaseCommand. 
'''On the Windows Form you have a Windows Button, that when you click will execute the functionality of another custom COM Class that Inherits ESRI.ArcGIS.ADF.BaseClasses.BaseTool.
'''This snippet would be inserted the Windows Form code behind file (.vb or .cs) and called as a result of the Windows Button click event.
'''</remarks>
Public Sub UseCustomToolOnWindowsForm(ByVal application As ESRI.ArcGIS.Framework.IApplication, ByVal uidValue As System.String)

  Dim UIDCls As ESRI.ArcGIS.esriSystem.IUID = New ESRI.ArcGIS.esriSystem.UIDClass
  UIDCls.Value = uidValue
  Dim commandItem As ESRI.ArcGIS.Framework.ICommandItem = application.Document.CommandBars.Find(UIDCls, False, False)

  If commandItem Is Nothing Then
    Exit Sub
  End If

  application.CurrentTool = commandItem

End Sub


Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Framework
  • ESRI.ArcGIS.System