Association between arcengine maps and la s

Source: Internet
Author: User

Association of arcengine maps and la s
The Association of maps and la s in arcengine is a headache! The linkage class provided in the help is just a [simple] linkage class (which I can say for the time being). It cannot achieve the expected results in actual projects, although map and layout are linked, the changed map and layout cannot be separated and saved. After two days of struggle, a feasible solution is finally found.

The linkage control is made into a control for convenient use.

Source code

Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. drawing;
Using system. Data;
Using system. text;
Using system. Windows. forms;
Using ESRI. ArcGIS. controls;
Using ESRI. ArcGIS. systemui;

Namespace forestmanagement. Controls
{
[Toolboxbitmapattribute (typeof (synchronizercontrol), "synchronizercontrol.bmp")]
Public partial class synchronizercontrol: usercontrol
{

Public synchronizercontrol ()
{
Initializecomponent ();
}
Private axmapcontrol mapcontrol;
[Description ("mapcontrol to bind"), category ("bind item")]
Public axmapcontrol mapcontrol
{
Get {return mapcontrol ;}
Set {mapcontrol = value ;}
}
Private axpagelayoutcontrol pagelayoutcontrol;
[Description ("pagelayoutcontrol to bind"), category ("bind item")]
Public axpagelayoutcontrol pagelayoutcontrol
{
Get {return pagelayoutcontrol ;}
Set {pagelayoutcontrol = value ;}
}

// The bound control class is the class in the help.
Private controlssynchronizer controlssyn;
Public controlssynchronizer controlssyn
{
Get {return controlssyn ;}
}
Private devcomponents. dotnetbar. Bar mapactivetool;
Public devcomponents. dotnetbar. Bar mapactivetool
{
Get {return mapactivetool ;}
Set {mapactivetool = value ;}
}
Private devcomponents. dotnetbar. Bar pageactivetool;
Public devcomponents. dotnetbar. Bar pageactivetool
{
Get {return pageactivetool ;}
Set {pageactivetool = value ;}
}
Private axtoolbarcontrol mapactivateml1;
Public axtoolbarcontrol mapactivateml1
{
Get {return mapactivateml1 ;}
Set {mapactivateml1 = value ;}
}
Private axtoolbarcontrol pageactivateml1;
Public axtoolbarcontrol pageactivateml1
{
Get {return pageactivateml1 ;}
Set {pageactivateml1 = value ;}
}

// Bind Control
Public void bingcontrols ()
{
Imapcontrol3 m_mapcontrol = (imapcontrol3) mapcontrol. object;
Ipagelayoutcontrol2 m_pagelayoutcontrol = (ipagelayoutcontrol2) pagelayoutcontrol. object;
Controlssyn = new controlssynchronizer (m_mapcontrol, m_pagelayoutcontrol );
Controlssyn. bindcontrols (true );
Controlssyn. addframeworkcontrol (mapactivateml1 );
Controlssyn. addframeworkcontrol (pageactivateml1 );

}

// Bind Control
Public void bindcontrolsintoolbar ()
{
Imapcontrol3 m_mapcontrol = (imapcontrol3) mapcontrol. object;
Ipagelayoutcontrol2 m_pagelayoutcontrol = (ipagelayoutcontrol2) pagelayoutcontrol. object;
Controlssyn = new controlssynchronizer (m_mapcontrol, m_pagelayoutcontrol );
Controlssyn. bindcontrols (true );
Controlssyn. addframeworkcontrol (mapactivateml1.object );
Controlssyn. addframeworkcontrol (pageactivateml1.object );
}
Private void synchronizercontrol_load (Object sender, eventargs E)
{

}

// Activate the map
Public void activatemap ()
{
Controlssyn. activatemap ();

}

// Activate the Layout
Public void activatepagelayout ()
{
Controlssyn. activatepagelayout ();
}

}
}

In the program, as long as mapcontrol, pagelayoutcontrol, mapactivetool, and pageactivetool of the control are set, the main interface load is to call bingcontrols () and to call activatemap () and activatepagelayout ()
But the association cannot be guaranteed. Some processing is done when the file is opened: the map is replaced when the map is opened.

I wrote a command to open the map. The source code is as follows, which is explained in detail. The above linkage control is used in the constructor.

The source code is as follows:

Public override void onclick ()
{
// Create a new openfile Dialog
Openfiledialog DLG = new openfiledialog ();
DLG. Filter = "map elements (*. mxd) | *. mxd ";
DLG. multiselect = false;
DLG. Title = "Open Map document ";
If (DLG. showdialog () = dialogresult. OK)
{
String docname = DLG. filename;

Imapdocument mapdoc = new mapdocumentclass ();
// Determine whether the document is encrypted. Open and load documents without encryption
If (mapdoc. get_ispresent (docname )&&! Mapdoc. get_ispasswordprotected (docname ))
{
Mapdoc. Open (docname, String. Empty );
// Load pagelayout first and assign the map to mapcontrol
M_controlssynchronizer.pagelayoutcontrol.loadmxfile (docname, null );
M_controlssynchronizer.replacemap (m_controlssynchronizer.pagelayoutcontrol.activeview.focusmap );
Mapdoc. Close ();
}

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/ybgiser/archive/2009/02/24/3932345.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.