MapControl corresponds to the data view of the ArcMap application and encapsulates the Map object. Map documents preauthored with the ArcMap application can be loaded into MapControl, eliminating the need to programmatically compose the cartography. See the following screen shot:
Loading map documents
The map document can be set at design time though the MapControl property pages (in development environments that support property page capability), and MapControl can be set to link or contain the map document. When linking, MapControl reads the map document whenever MapControl is created on the container and display the most recent updates to the map document. When containing, MapControl copies the contents of the map document into MapControl but will not display any further updates made to the map document from that point forward. Containing increases the size of the application executable containing MapControl.
Alternatively, a map document can be loaded into the MapControl programmatically using the CheckMxFile method to determine whether the document is valid and the LoadMxFile method to load the map document. The ReadMxMaps method can be used in conjunction with the LoadMxFile method to load a specific Map from a map document into the MapControl. See the following code example:
[C#]
string filePath = @"C:\Temp\myDocument.mxd";
if (axMapControl1.CheckMxFile(filePath)) axMapControl1.LoadMxFile(filePath,Type.Missing,Type.Missing);
[VB.NET]
Dim sFilePath AsString
sFilePath = "C:\Temp\myDocument.mxd"If AxMapControl1.CheckMxFile(sFilePath) Then AxMapControl1.LoadMxFile(sFilePath, "", "")
Saving map documents
In addition to reading map documents, MapControl can also write map documents (*.mxd). MapControl implements the IMxdContents interface that enables the MapDocument object to write the contents of the MapControl to a new map document.
MapControl's display area can be altered by using the VisibleRegion property to change the shape of the display area and the Rotation property to alter the angle at which data is drawn on the display. Helper methods such as TrackRectangle, TrackPolygon, TrackLine, and TrackCircle exist on the MapControl for tracking or "rubber banding" shapes on the display. For example, to zoom in on the display, set the Envelope returned from the TrackRectangle method into the Extent property. Shapes can be drawn on the display with the DrawShape, DrawText, and FlashShape methods, typically in the IMapControlEvents2.OnAfterDraw event.