Exemplo n.º 1
0
 private void method_0(IMapDocument imapDocument_0)
 {
     if (this.object_0 is IPageLayoutControl2)
     {
         imapDocument_0.ReplaceContents(((IPageLayoutControl2)this.object_0).PageLayout as IMxdContents);
         try
         {
             imapDocument_0.Save(true, true);
         }
         catch (Exception)
         {
         }
     }
     else if (this.object_0 is IMapControl2)
     {
         imapDocument_0.ReplaceContents(((IMapControl2)this.object_0).Map as IMxdContents);
         try
         {
             imapDocument_0.Save(true, true);
         }
         catch (Exception)
         {
         }
     }
     else if (this.object_0 is MapAndPageLayoutControls)
     {
         imapDocument_0.ReplaceContents(
             (this.object_0 as MapAndPageLayoutControls).PageLayoutControl.PageLayout as IMxdContents);
         imapDocument_0.Save(true, true);
     }
 }
Exemplo n.º 2
0
        private void Save_btn_Click(object sender, EventArgs e)
        {
            if (axMapControl1.DocumentFilename == null)
            {
                SaveMapAs();
            }
            if (m_bDocModified == false)
            {
                return;
            }
            try
            {
                if (axMapControl1.Map.LayerCount == 0)
                {
                    return;
                }
                if (axMapControl1.DocumentFilename != null && axMapControl1.CheckMxFile(axMapControl1.DocumentFilename))
                {
                    if (m_pMapDocument != null)
                    {
                        m_pMapDocument.Close();
                        m_pMapDocument = null;
                    }
                    m_pMapDocument = new MapDocumentClass();                            //实例化
                    m_pMapDocument.Open(axMapControl1.DocumentFilename, "");            //必须的一步,用于将AxMapControl的实例的DocumentFileName传递给pMapDoc的
                    if (m_pMapDocument.get_IsReadOnly(m_pMapDocument.DocumentFilename)) //判断是否只读
                    {
                        MessageBox.Show("文件只读!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        m_pMapDocument.Close();
                        return;
                    }
                    m_pMapDocument.ReplaceContents((IMxdContents)axMapControl1.Map); //重置
                    IObjectCopy lip_ObjCopy = new ObjectCopyClass();                 //使用Copy,避免共享引用
                    axMapControl1.Map = (IMap)lip_ObjCopy.Copy(m_pMapDocument.get_Map(0));
                    lip_ObjCopy       = null;
                    m_pMapDocument.Save(m_pMapDocument.UsesRelativePaths, true);
                    axMapControl1.DocumentFilename = m_pMapDocument.DocumentFilename;
                    this.Text      = this.Text + "  -  " + axMapControl1.DocumentFilename;
                    m_bDocModified = false;

                    FileInfo fi = new FileInfo(m_pMapDocument.DocumentFilename);
                    Global.m_sMxdPath = fi.GetDirectory();
                    MessageBox.Show("保存完成!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }