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 />

5. Build and run the application. Right-click the PageLayoutControl’s display<br />

area to display the popup menu, and navigate around the page layout.<br />

Controlling label editing in the TOCControl<br />

By default, the TOCControl allows users to automatically toggle the visibility of<br />

layers and to change map and layer names as they appear in the table of contents.<br />

You will add code to prevent users from editing a name and replacing it with an<br />

empty string.<br />

1. Add the following code to the beginning of the Form_Load event.<br />

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

{<br />

// Set label editing to manual.<br />

axTOCControl1.LabelEdit = esriTOCControlEdit.esriTOCControlManual;<br />

}<br />

// Add generic commands.<br />

2. Display the form in design mode, select AxTOCControl1 from the Properties<br />

window, and display the AxTOCControl events. Double-click<br />

OnEndLabelEdit to add an event handler to the code window.<br />

3. Add the following code to the axTOCControl_OnEndLabelEdit event:<br />

private void axTOCControl1_OnEndLabelEdit(object sender,<br />

ESRI.<strong>ArcGIS</strong>.TOCControl.ITOCControlEvents_OnEndLabelEditEvent e)<br />

{<br />

// If the new label is an empty string, then prevent the edit.<br />

string newLabel = e.newLabel;<br />

if (newLabel.Trim() == "")<br />

{<br />

e.canEdit = false;<br />

}<br />

}<br />

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

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

Saved successfully!

Ooh no, something went wrong!