18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

BUILDING APPLICATIONS WITH WINDOWS CONTROLS<br />

15. In the Class View window, navigate to the BaseCommand Enabled property<br />

and right-click to display the context menu. Click Add, then Override to add<br />

the property to the code window.<br />

16. Add the following code to override the default Enabled value as implemented<br />

by the BaseTool class.<br />

The ICommand_OnCreate event is passed a<br />

handle or hook to the application that the<br />

command will work with. In this case it can be a<br />

MapControl, PageLayoutControl, or<br />

ToolbarControl. Rather than adding code into the<br />

OnCreate event to determine the type of hook<br />

that is being passed to the command, you will<br />

use the HookHelper to handle this. A command<br />

or tool needs to know how to handle the hook<br />

it gets passed, so a check is needed to determine<br />

the type of <strong>ArcGIS</strong> Control that has been<br />

passed. The HookHelper is used to hold the hook<br />

and return the ActiveView regardless of the type<br />

of hook (in this case a MapControl,<br />

PageLayoutControl, or ToolbarControl).<br />

public override bool Enabled<br />

{<br />

get<br />

{<br />

// Set the enabled property.<br />

if (m_HookHelper.ActiveView != null)<br />

{<br />

return true;<br />

}<br />

else<br />

{<br />

return false;<br />

}<br />

}<br />

}<br />

17. In the Class View window, navigate to the BaseTool OnMouseDown method<br />

and right-click to display the context menu. Click Add, then Override to add<br />

the property to the code window.<br />

18. Add the following code to the override the default OnMouseDown functionality<br />

as implemented by the BaseTool class.<br />

public override void OnMouseDown(int Button, int Shift, int X, int Y)<br />

{<br />

base.OnMouseDown (Button, Shift, X, Y);<br />

// Get the active view.<br />

IActiveView activeView = m_HookHelper.ActiveView;<br />

// Create a new text element.<br />

ITextElement textElement = new TextElementClass();<br />

// Create a text symbol.<br />

ITextSymbol textSymbol = new TextSymbolClass();<br />

textSymbol.Size = 25;<br />

// Set the text element properties.<br />

textElement.Symbol = textSymbol;<br />

textElement.Text = DateTime.Now.ToShortDateString();<br />

// QI for IElement.<br />

IElement element = (IElement) textElement;<br />

// Create a page point.<br />

IPoint point = new PointClass();<br />

point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(X,Y);<br />

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

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

Saved successfully!

Ooh no, something went wrong!