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

// Set the element's geometry.<br />

element.Geometry = point;<br />

Setting the Register for COM Interop property<br />

to True will invoke the Assembly Registration<br />

Tool (Regasm.exe). This will add the information<br />

about the class to the registry that a COM<br />

client would expect to find.<br />

If the Register for COM Interop property is<br />

disabled, check that the project is a C# class<br />

library type.<br />

A new GUID can be generated by using the<br />

GuidGen.exe utility included with Visual Studio<br />

.NET or by selecting Create GUID from the<br />

Tools menu. The GUID should be specified in the<br />

format shown, without curly brackets.<br />

// Add the element to the graphics container.<br />

activeView.GraphicsContainer.AddElement(element, 0);<br />

// Refresh the graphics.<br />

activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null,<br />

null);<br />

}<br />

19. <strong>ArcGIS</strong> <strong>Engine</strong> expects the custom command to be a COM class; therefore<br />

you must specify that the .NET class you have created is also exposed as a<br />

COM class by creating a COM callable wrapper for it. In the Solution Explorer<br />

window, right-click the Commands project and select Properties from<br />

the context menu.<br />

20. In the project Property Pages dialog box, select Configuration Properties,<br />

then click Build. In the right pane, change the Register for COM Interop<br />

property to True. Click OK.<br />

21. In the code window of the AddDateTool class add the following code to the<br />

beginning of the AddDateTool class declaration to specify attributes required<br />

by COM.<br />

[ClassInterface(ClassInterfaceType.None)]<br />

[Guid("D880184E-AC81-47E5-B363-781F4DC4528F")]<br />

22. Add the following code to the AddDateTool class after the member variables.<br />

The code defines functions that register and unregister the AddDateTool class<br />

to the ESRI Controls Commands component category using the categories<br />

utility.<br />

// Register in the 'ESRI Controls Commands' component category.<br />

#region Component Category Registration<br />

[ComRegisterFunction()]<br />

[ComVisible(false)]<br />

static void RegisterFunction(String sKey)<br />

{<br />

string fullKey = sKey.Remove(0, 18) + @"\Implemented Categories";<br />

Microsoft.Win32.RegistryKey regKey =<br />

Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(fullKey, true);<br />

if (regKey != null)<br />

{<br />

regKey.CreateSubKey("{B284D891-22EE-4F12-A0A9-<br />

B1DDED9197F4}");<br />

}<br />

}<br />

[ComUnregisterFunction()]<br />

[ComVisible(false)]<br />

static void UnregisterFunction(String sKey)<br />

{<br />

string fullKey = sKey.Remove(0, 18) + @"\Implemented Categories";<br />

Microsoft.Win32.RegistryKey regKey =<br />

Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(fullKey, true);<br />

if (regKey != null)<br />

350 • <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> <strong>Guide</strong>

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

Saved successfully!

Ooh no, something went wrong!