TOCControl右鍵菜單

來源:互聯網
上載者:User

標籤:style   io   使用   ar   資料   sp   代碼   log   on   

       新接觸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);

   就這樣。

TOCControl右鍵菜單

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.