AE注册命令和ToolbarControl添加Item

 [Guid("D096C0A0-9B80-4F4C-9FAF-F8095C10785C")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("CalculateContourTask.ComOpenShapeFile")]
    public sealed class ComOpenShapeFile : BaseCommand

    {

       //注册

        [ComRegisterFunction()]
        [ComVisible(false)]
        static void RegisterFunction(Type registerType)
        {
            string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
            ControlsCommands.Register(regKey);

        }

        //注销

        [ComUnregisterFunction()]
        [ComVisible(false)]
        static void UnregisterFunction(Type registerType)
        {
            string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
            ControlsCommands.Unregister(regKey);
        }
        IMapControl2 m_MapControl;
        public ComOpenShapeFile()
        {
            string str = "打开地图文档";
            base.m_category = str;
            base.m_caption = str;
            base.m_message = str;
            base.m_toolTip = str;
            base.m_name = str;
            try
            {
                string strBmp = GetType().Name + ".bmp";
                base.m_bitmap = new Bitmap(GetType(), strBmp);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
            }

        }

        //重载创建命令

        public override void OnCreate(object hook)
        {
            if (hook == null)
            {
                return;
            }
            if (hook is IToolbarControl)
            {
                IToolbarControl pToolBar = hook as IToolbarControl;
                m_MapControl = pToolBar.Buddy as IMapControl2;
            }else if (hook is IMapControl2)
            {
                m_MapControl = hook as IMapControl2;
            }

        }

       //重载点击

        public override void OnClick()
        {
            string[] strShapeFile = AEOpenFile.OpenShapeFile();  //自定义打开文件函数
            if (strShapeFile[0] == "")
            {
                return;
            }
            IMapDocument pMapDoc = new MapDocumentClass();
            if (pMapDoc.get_IsPresent(strShapeFile[2]) && !pMapDoc.get_IsPasswordProtected(strShapeFile[2]))
            {
                m_MapControl.AddShapeFile(strShapeFile[0], strShapeFile[1]);
                m_MapControl.ActiveView.Refresh();
                pMapDoc.Close();
            }
            return;
        }

    }

结果如下:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值