18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

BUILDING APPLICATIONS WITH WINDOWS CONTROLS<br />

OnPageLayoutReplaced event will be triggered whenever a document is<br />

loaded into the PageLayoutControl.<br />

private void axPageLayoutControl1_OnPageLayoutReplaced(object sender,<br />

ESRI.<strong>ArcGIS</strong>.PageLayoutControl.IPageLayoutControlEvents_OnPageLayoutReplacedEvent<br />

e)<br />

{<br />

// Load the same preauthored map document into the MapControl.<br />

axMapControl1.LoadMxFile(axPageLayoutControl1.DocumentFilename,null,<br />

null);<br />

// Set the extent of the MapControl to the full extent of the data.<br />

axMapControl1.Extent = axMapControl1.FullExtent;<br />

}<br />

Setting the TOCControl and ToolbarControl buddy controls<br />

For the purpose of this application, the TOCControl and ToolbarControl will<br />

work in conjunction with the PageLayoutControl, rather than the MapControl.<br />

To do this the PageLayoutControl must be set as the buddy control. The<br />

TOCControl uses the buddy’s ActiveView to populate itself with maps, layers,<br />

and symbols, while any command, tool, or menu items present on the<br />

ToolbarControl will interact with the buddy control’s display.<br />

1. In the Form_Load event enter the following after the load document code:<br />

private void Form1_Load(object sender, System.EventArgs e)<br />

{<br />

// Load a preauthored map document into the PageLayoutControl using<br />

// relative paths.<br />

string fileName =<br />

@"..\..\..\..\..\..\..\..\Data\\<strong>ArcGIS</strong>_<strong>Engine</strong>_<strong>Developer</strong>_<strong>Guide</strong>\Gulf of St.<br />

Lawrence.mxd";<br />

if (axPageLayoutControl1.CheckMxFile(fileName))<br />

{<br />

axPageLayoutControl1.LoadMxFile(fileName,"");<br />

}<br />

// Set buddy controls.<br />

axTOCControl1.SetBuddyControl(axPageLayoutControl1);<br />

axToolbarControl1.SetBuddyControl(axPageLayoutControl1);<br />

}<br />

2. Build and run the application. The map document is loaded into the<br />

PageLayoutControl, and the TOCControl lists the data layers in the map<br />

document. Use the TOCControl to toggle layer visibility by checking and<br />

unchecking the boxes. By default, the focus map of the map document is<br />

loaded into the MapControl. At this point the ToolbarControl is empty because<br />

no commands have been added to it. Try resizing the form, and note that<br />

the controls do not change size.<br />

Chapter 6 • <strong>Developer</strong> scenarios • 337

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!