⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myfullextentcommand.cs

📁 ArcGIS Engine ControlsCommands CSharp的一个例子
💻 CS
字号:
// Copyright 2006 ESRI
//
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
//
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
//
// See use restrictions at /arcgis/developerkit/userestrictions.

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Resources;
using System.Reflection;

using System.Drawing;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;

namespace CSharpMyFullExtent
{
    /// <summary>
    /// Command that works in ArcMap/Map/PageLayout
    /// </summary>
    [Guid("4f4e73b1-40c3-44a5-8729-d403b7b3d779")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("CSharpMyFullExtent.MyFullExtentCommand")]
    public sealed class MyFullExtentCommand : 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);
            MxCommands.Register(regKey);
            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);
            MxCommands.Unregister(regKey);
            ControlsCommands.Unregister(regKey);
        }

        #endregion
        #endregion

        private IHookHelper m_hookHelper = null;
        public MyFullExtentCommand()
        {
            //
            // TODO: Define values for the public properties
            //
            base.m_category = "CustomCommands"; //localizable text
            base.m_caption = "My Full Extent";  //localizable text
            base.m_message = "My Full Extent";  //localizable text 
            base.m_toolTip = "My Full Extent";  //localizable text
            base.m_name = "MyCommands_MyFullExtent";   //unique id, non-localizable (e.g. "MyCategory_MyCommand")

            //As part of your deployment strategy you must register the name of the WinHelp file (*.hlp)
            //as a new string value in: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Help
            //or provide the full path name.
            base.m_helpFile = "MyHelpFile.hlp";

            //The Context Help ID as defined when compiling the RTF file into the HelpFile
            base.m_helpID = 1234;

            ResourceManager rm = new ResourceManager("CSharpMyFullExtent.Resources", Assembly.GetExecutingAssembly());
            base.m_bitmap = (System.Drawing.Bitmap)rm.GetObject("CommandImage");
        }

        #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;

            try
            {
                m_hookHelper = new HookHelperClass();
                m_hookHelper.Hook = hook;
                if (m_hookHelper.ActiveView == null)
                    m_hookHelper = null;
            }
            catch
            {
                m_hookHelper = null;
            }

            if (m_hookHelper == null)
                base.m_enabled = false;
            else
                base.m_enabled = true;

        }

        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            //Get IActiveView interface
            IActiveView pActiveView = m_hookHelper.FocusMap as IActiveView;

            //Set the extent to the full extent
            pActiveView.Extent = pActiveView.FullExtent;

            //Refresh the active view
            pActiveView.Refresh();
        }

        #endregion
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -