zoukankan      html  css  js  c++  java
  • TOCControl右键菜单

           新接触TOCControl空间的自定义菜单,其功能强大令人叹为观止。可用AddItem添加自定义Command、menu或者esriControls下的Command、menu;了解使用esriControls下的Command、menu,可以为开发者省下大量的时间。举例说明如下:自定义了一个添加图层的命令(在其中特别注意CustomProperty这个属性,它可以灵活附加传递多种数据)。

       class AddLayer : BaseCommand
        {
            private IMapControl3 m_mapControl;

            public AddLayer()
            {
                base.m_caption = "添加地图文档";
            }

            public override void OnClick()
            {
                ILayer layer = (ILayer)m_mapControl.CustomProperty;
                m_mapControl.Map.DeleteLayer(layer);
                OpenFileDialog openFileDialog1 = (OpenFileDialog)m_mapControl.CustomProperty;
                openFileDialog1.Title = "打开地图文档";
                openFileDialog1.Filter = "map documents(*.mxd)|*.mxd";
                openFileDialog1.ShowDialog();
                string filePath = openFileDialog1.FileName;
                if (m_mapControl.CheckMxFile(filePath))
                {
                    m_mapControl.MousePointer = esriControlsMousePointer.esriPointerHourglass;
                    m_mapControl.LoadMxFile(filePath);
                    m_mapControl.MousePointer = esriControlsMousePointer.esriPointerDefault;
                }
                else
                {
                    MessageBox.Show("地图文档无效!");
                }
            }

            public override void OnCreate(object hook)
            {
                m_mapControl = (IMapControl3)hook;
            }
        }

       toolbarMenu.AddItem(new AddLayer(), -1, 0, false, esriCommandStyles.esriCommandStyleTextOnly);

       但其实足够了解esriControls下的现成命令的话,上述代码可以浓缩为:

         toolbarMenu.AddItem("esriControls.ControlsOpenDocCommand", -1, 0, false,esriCommandStyles.esriCommandStyleIconOnly);

       就这样。

  • 相关阅读:
    抽象类与接口的区别
    模板模式(Template Pattern)
    KVM虚拟化
    find文本处理(locate)实例学习记录
    AWK-文本处理测试实例记录
    Linux系统中如何查找大文件
    吞吐量和Iops、测试工具FIO使用
    linux了解
    了解docker
    语言资源国际化
  • 原文地址:https://www.cnblogs.com/qingwufeiyang/p/3969791.html
Copyright © 2011-2022 走看看