About the Creating a zoom factor extension that works with a ToolbarControl Sample
[C#]
SetZoomFactor.cs
using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.ADF.BaseClasses; using ESRI.ArcGIS.ADF.CATIDs; using System.Runtime.InteropServices; using System.Windows.Forms; namespace ZoomFactorExtensionCSharp { [ClassInterface(ClassInterfaceType.None)] [Guid("e9ea3574-e45f-4197-9e07-9c0c323f8791")] public sealed class SetZoomFactor: BaseCommand { //The HookHelper object that deals with the hook passed to the OnCreate event private IHookHelper m_HookHelper = new HookHelperClass(); #region "Component Category Registration" [ComRegisterFunction()] static void Reg(string regKey) { ControlsCommands.Register(regKey); } [ComUnregisterFunction()] static void Unreg(string regKey) { ControlsCommands.Unregister(regKey); } #endregion public SetZoomFactor() { //Set the command properties base.m_caption = "Set Variable Zoom"; base.m_message = "Set Variable Zoom"; base.m_toolTip = "Set Variable Zoom"; base.m_category = "ZoomExtension Sample(CSharp)"; base.m_name = "ZoomExtension Sample(CSharp)_Set Variable Zoom"; base.m_bitmap = new System.Drawing.Bitmap(GetType().Assembly.GetManifestResourceStream("Commands.zoomfactor.bmp")); } public override void OnCreate(object hook) { //Not implemented } public override bool Enabled { get { //Get the extension manager IExtensionManager extensionManager = new ExtensionManagerClass(); //Get the extension from the extension manager IExtension extension = extensionManager.FindExtension("Zoom Factor Extension"); //Get the state of the extension IExtensionConfig extensionConfig = (IExtensionConfig) extension; if (extensionConfig != null) { if (extensionConfig.State == esriExtensionState.esriESEnabled) return true; else return false; } else { return false; } } } public override void OnClick() { //Get the extension manager ExtensionManager extensionManager = new ExtensionManagerClass(); //Get the extension from the extension manager IExtension extension = extensionManager.FindExtension("Zoom Factor Extension"); IZoomExtension zoomExtension = (IZoomExtension) extension; double zoomFactor = zoomExtension.ZoomFactor; //Get a zoom factor from the user InputFormResult res = InputForm.ShowModal(null,"Enter a zoom factor","ZoomExtension Sample", zoomExtension.ZoomFactor.ToString() ); if (res.Result == DialogResult.Cancel) return; string zoomString = res.InputString; if (zoomString.Trim() == "") return; //Set the zoom factor if (System.Char.IsNumber(zoomString,0) == true) zoomExtension.ZoomFactor = System.Convert.ToDouble(zoomString); } } }
[Visual Basic .NET]
SetZoomFactor.vb
Option Explicit On Imports ESRI.ArcGIS.Carto Imports ESRI.ArcGIS.Geometry Imports ESRI.ArcGIS.esriSystem Imports ESRI.ArcGIS.Controls Imports ESRI.ArcGIS.ADF.BaseClasses Imports ESRI.ArcGIS.ADF.CATIDs Imports System.Runtime.InteropServices <ComClass(SetZoomFactor.ClassId, SetZoomFactor.InterfaceId, SetZoomFactor.EventsId)> _ Public NotInheritable Class SetZoomFactor Inherits BaseCommand Private m_Hookhelper As IHookHelper #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 = "0f65b096-8d64-4f03-a69d-0f976c32e6cf" Public Const InterfaceId As String = "83de6bce-2cf7-46e6-af2c-e396a694a34c" Public Const EventsId As String = "d1125967-20bc-4e55-9fdd-de5d831637f3" #End Region #Region "Component Category Registration" <ComRegisterFunction()> _ Public Shared Sub Reg(ByVal regKey As String) ControlsCommands.Register(regKey) End Sub <ComUnregisterFunction()> _ Public Shared Sub Unreg(ByVal regKey As String) ControlsCommands.Unregister(regKey) End Sub #End Region Public Sub New() MyBase.New() 'Create an IHookHelper object m_Hookhelper = New HookHelperClass 'Set the command properties MyBase.m_caption = "Set Variable Zoom" MyBase.m_message = "Set Variable Zoom" MyBase.m_toolTip = "Set Variable Zoom" MyBase.m_category = "ZoomExtension Sample(VB.NET)" MyBase.m_name = "ZoomExtension Sample(VB.NET)_Set Variable Zoom" MyBase.m_bitmap = New System.Drawing.Bitmap(GetType(ZoomOut).Assembly.GetManifestResourceStream(GetType(ZoomOut), "zoomfactor.bmp")) End Sub Public Overrides ReadOnly Property Enabled() As Boolean Get 'Get the extension manager Dim pExtensionManager As IExtensionManager = New ExtensionManagerClass 'Get the extension from the extension manager Dim pExtension As IExtension pExtension = pExtensionManager.FindExtension("Zoom Factor Extension") 'Get the state of the extension Dim pExtensionConfig As IExtensionConfig pExtensionConfig = pExtension If (Not pExtensionConfig Is Nothing) Then If (pExtensionConfig.State = esriExtensionState.esriESEnabled) Then Return True Else Return False End If Else Return False End If End Get End Property Public Overrides Sub OnClick() 'Get the extension manager Dim pExtensionManager As IExtensionManager pExtensionManager = New ExtensionManagerClass 'Get the extension from the extension manager Dim pExtension As IExtension pExtension = pExtensionManager.FindExtension("Zoom Factor Extension") 'Get the zoom extension interface Dim pZoomExtension As IZoomExtension pZoomExtension = pExtension 'Get a zoom factor from the user Dim zoomString As String zoomString = InputBox("Enter Zoom Factor", "ZoomExtension Sample", CStr(pZoomExtension.ZoomFactor)) 'Set the zoom factor If IsNumeric(zoomString) Then pZoomExtension.ZoomFactor = CDbl(zoomString) End Sub Public Overrides Sub OnCreate(ByVal hook As Object) 'Not implemented End Sub End Class