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

       就这样。

  • 相关阅读:
    ng2-bootstrap的modal嵌套时无法滚动的情况
    oracle自动补0
    webservice 从客户端中检测到有潜在危险的 Request.Form 值
    树莓派花生壳
    ubuntu E: Could not get lock /var/lib/dpkg/lock
    树莓派配置静态ip
    解决PL/SQL查询结果乱码的问题
    批处理脚本命令行方式关闭Windows服务
    最简单的分享到微博代码
    Select的onchange事件
  • 原文地址:https://www.cnblogs.com/qingwufeiyang/p/3969791.html
Copyright © 2011-2022 走看看