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

       就这样。

  • 相关阅读:
    智能移动机器人背后蕴含的技术——激光雷达
    Kalman Filters
    Fiddler抓HttpClient的包
    VSCode开发WebApi EFCore的坑
    WPF之小米Logo超圆角的实现
    windows react打包发布
    jenkins in docker踩坑汇总
    Using ML.NET in Jupyter notebooks 在jupyter notebook中使用ML.NET ——No design time or full build available
    【Linux知识点】CentOS7 更换阿里云源
    【Golang 报错】exec gcc executable file not found in %PATH%
  • 原文地址:https://www.cnblogs.com/qingwufeiyang/p/3969791.html
Copyright © 2011-2022 走看看