About the Editing using a custom form Sample
[C#]
EditCmd.cs
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Controls;
namespace EditingUsingCustomForm
{
/// <summary>
/// Summary description for Edit.
/// </summary>
[Guid("993a58bc-000f-4aef-b437-68151c858889")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("EditingUsingCustomForm.Edit")]
public sealed class EditCmd : BaseCommand
{
#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;
public EditCmd()
{
base.m_category = ""; //Command won't get registered in category as it is in an EXE
base.m_caption = "Edit Highways";
base.m_message = "Edit Highways";
base.m_toolTip = "Edit Highways";
base.m_name = "Edit Highways";
try
{
string bitmapResourceName = GetType().Name + ".bmp";
base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
}
}
#region Overriden Class Methods
/// <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;
if (m_hookHelper == null)
m_hookHelper = new HookHelperClass();
m_hookHelper.Hook = hook;
}
/// <summary>
/// Occurs when this command is clicked
/// </summary>
public override void OnClick()
{
EditorForm editorForm = new EditorForm();
editorForm.Owner = EditHelper.TheMainForm;
editorForm.Show();
}
public override bool Enabled
{
get
{
return !(EditHelper.IsEditorFormOpen);
}
}
#endregion
}
}
[Visual Basic .NET]
EditCmd.vb
Imports System.Runtime.InteropServices
Imports System.Drawing
Imports ESRI.ArcGIS.ADF.BaseClasses
Imports ESRI.ArcGIS.ADF.CATIDs
Imports ESRI.ArcGIS.Controls
<ComClass(EditCmd.ClassId, EditCmd.InterfaceId, EditCmd.EventsId), _
ProgId("EditingUsingCustomForm.EditCmd")> _
Public NotInheritable Class EditCmd
Inherits BaseCommand
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "a52b2735-0959-4c21-8764-fbf274f2ab8d"
Public Const InterfaceId As String = "66f50015-dfa3-4fad-adae-0c8cae0479c5"
Public Const EventsId As String = "a7c76c56-7ebf-411e-86d7-56c170c05980"
#End Region
#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)
'Add any COM registration code after the ArcGISCategoryRegistration() call
End Sub
<ComUnregisterFunction(), ComVisibleAttribute(False)> _
Public Shared Sub UnregisterFunction(ByVal registerType As Type)
' Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType)
'Add any COM unregistration code after the ArcGISCategoryUnregistration() call
End Sub
#Region "ArcGIS Component Category Registrar generated code"
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
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
Private m_hookHelper As IHookHelper
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
MyBase.m_category = "" 'Command won't get registered in category as it is in an EXE
MyBase.m_caption = "Edit Highways"
MyBase.m_message = "Edit Highways"
MyBase.m_toolTip = "Edit Highways"
MyBase.m_name = "Edit Highways"
Try
'TODO: change bitmap name if necessary
Dim bitmapResourceName As String = Me.GetType().Name + ".bmp"
MyBase.m_bitmap = New Bitmap(Me.GetType(), bitmapResourceName)
Catch ex As Exception
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap")
End Try
End Sub
Public Overrides Sub OnCreate(ByVal hook As Object)
If m_hookHelper Is Nothing Then m_hookHelper = New HookHelperClass
If Not hook Is Nothing Then
m_hookHelper.Hook = hook
End If
End Sub
Public Overrides Sub OnClick()
Dim editorForm As EditorForm = New EditorForm()
editorForm.Owner = EditHelper.TheMainForm
editorForm.Show()
End Sub
Public Overrides ReadOnly Property Enabled() As Boolean
Get
Return Not (EditHelper.IsEditorFormOpen)
End Get
End Property
End Class