ArcObjects Library Reference  

SnapSettingsCommand

About the Managing snap agents Sample

[C#]

SnapSettingsCommand.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Controls;

namespace Core
{
  /// <summary>
  /// Launches the SnapEditorForm
  /// </summary>
  [Guid("F83AE05F-3E88-428A-B2E2-C6428081C61A")]
  [ClassInterface(ClassInterfaceType.None)]
  [ProgId("SnapCommands_CS.SnapSettingsCommand")]
  public sealed class SnapSettingsCommand : BaseCommand
  {
    #region COM Registration Function(s)
    [ComRegisterFunction()]
    [ComVisible(false)]
    public static void RegisterFunction(Type registerType)
    {
      // Required for ArcGIS Component Category Registrar support
      ArcGISCategoryRegistration(registerType);      
    }

    [ComUnregisterFunction()]
    [ComVisible(false)]
    public static void UnregisterFunction(Type registerType)
    {
      // Required for ArcGIS Component Category Registrar support
      ArcGISCategoryUnregistration(registerType);
    }

    #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

    SnapEditor snapEditor;

    public SnapSettingsCommand()
    {
    }
     

    #region ICommand Members

    public override void OnClick()
    {
      //The snap editor form requires an edit session (e.g. in order to read the target layer and to set the snap tips)
      IEngineEditor editor = new EngineEditorClass();
      if (editor.EditState != esriEngineEditState.esriEngineStateEditing)
      {
        System.Windows.Forms.MessageBox.Show("Please start an edit session");
        return;
      }

      //Show the snap settings form
      if (snapEditor == null || snapEditor.IsDisposed)
      {        
        snapEditor = new SnapEditor();          
      }
      snapEditor.Show();
      snapEditor.BringToFront();
    }

    public override string Message
    {
      get
      {
        return "SnapSettingsCommand";
      }
    }

    public override int Bitmap
    {
      get
      {
        return 0;
      }
    }

    /// <summary>
    /// Occurs when this command is created
    /// </summary>
    /// <param name="hook">Instance of the application</param>
    public override void OnCreate(object hook)
    {
      if (hook == null)
        return;         
    }

    public override string Caption
    {
      get
      {
        return "SnapSettingsCommandCS";
      }
    }

    public override string Tooltip
    {
      get
      {
        return "SnapSettingsCommand";
      }
    }

    public override int HelpContextID
    {
      get
      {
        return 0;
      }
    }

    public override string Name
    {
      get
      {
        return "SnapCommands_CS_SnapSettingsCommand";
      }
    }

    public override bool Checked
    {
      get
      {
        return false;
      }
    }

    public override bool Enabled
    {
      get
      {
        return true;
      }
    }

    public override string HelpFile
    {
      get
      {
        return null;
      }
    }

    public override string Category
    {
      get
      {
        return "Developer Samples";
      }
    }
    #endregion
  }
}
[Visual Basic .NET]

SnapSettingsCommand.vb

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports ESRI.ArcGIS.ADF.CATIDs
Imports ESRI.ArcGIS.ADF.BaseClasses
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.SystemUI
Imports ESRI.ArcGIS.Controls
 
Namespace Core
  
  <Guid("C219533C-2B2C-4DC9-9D85-17656C1EAD63"), ClassInterface(ClassInterfaceType.None), ProgId("SnapCommands_VB.SnapSettingsCommand")> _
  Public Class SnapSettingsCommand
    Inherits BaseCommand

#Region "COM Registration Function(s)"
    <ComRegisterFunction(), ComVisibleAttribute(False)> _
    Public Shared Sub RegisterFunction(ByVal registerType As Type)
      ' Required for ArcGIS Component Category Registrar support
      ArcGISCategoryRegistration(registerType)
    End Sub

    <ComUnregisterFunction(), ComVisibleAttribute(False)> _
    Public Shared Sub UnregisterFunction(ByVal registerType As Type)
      ' Required for ArcGIS Component Category Registrar support
      ArcGISCategoryUnregistration(registerType)
    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(ByVal 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(ByVal 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

    Dim snapEditor As SnapEditor

    Public Sub New()
    End Sub


#Region "ICommand Members"

    Public Overrides Sub OnClick()
      'The snap editor form requires an edit session (e.g. in order to read the target layer and to set the snap tips)
      Dim editor As IEngineEditor = New EngineEditorClass()
      If editor.EditState <> esriEngineEditState.esriEngineStateEditing Then
        System.Windows.Forms.MessageBox.Show("Please start an edit session")
        Return
      End If

      'Show the snap editor form
      If ((snapEditor Is Nothing) OrElse (snapEditor.IsDisposed)) Then
        snapEditor = New SnapEditor()
      End If
      snapEditor.Show()
      snapEditor.BringToFront()
    End Sub

    Public Overrides ReadOnly Property Message() As String
      Get
        Return "SnapSettingsCommand"
      End Get
    End Property

    Public Overrides ReadOnly Property Bitmap() As Integer
      Get
        Return 0
      End Get
    End Property

    '/ <summary>
    '/ Occurs when this command is created
    '/ </summary>
    '/ <param name="hook">Instance of the application</param>
    Public Overrides Sub OnCreate(ByVal hook As Object)
      If hook Is Nothing Then
        Return
      End If
    End Sub

    Public Overrides ReadOnly Property Caption() As String
      Get
        Return "SnapSettingsCommandVB"
      End Get
    End Property

    Public Overrides ReadOnly Property Tooltip() As String
      Get
        Return "SnapSettingsCommand"
      End Get
    End Property

    Public Overrides ReadOnly Property HelpContextID() As Integer
      Get
        Return 0
      End Get
    End Property

    Public Overrides ReadOnly Property Name() As String
      Get
        Return "SnapCommands_VB_SnapSettingsCommand"
      End Get
    End Property

    Public Overrides ReadOnly Property Checked() As Boolean
      Get
        Return False
      End Get
    End Property

    Public Overrides ReadOnly Property Enabled() As Boolean
      Get
        Return True
      End Get
    End Property

    Public Overrides ReadOnly Property HelpFile() As String
      Get
        Return Nothing
      End Get
    End Property

    Public Overrides ReadOnly Property Category() As String
      Get
        Return "Developer Samples"
      End Get
    End Property
#End Region
  End Class
End Namespace

'----------------------------------------------------------------
' Converted from C# to VB .NET using CSharpToVBConverter(1.2).
' Developed by: Kamal Patel (http://www.KamalPatel.net) 
'----------------------------------------------------------------