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

Customizing the ToolbarControl<br />

In addition to adding <strong>ArcGIS</strong> <strong>Engine</strong> commands and tools to the ToolbarControl<br />

in the Form_Load event, you can also add them by customizing the<br />

ToolbarControl and using the Customize dialog box. To do this you will place the<br />

ToolbarControl in customize mode and display the Customize dialog box.<br />

1. Add the following member variables to the class:<br />

Visual Studio .NET provides the ability to specify<br />

functions that execute when an assembly<br />

exposed for COM interop is registered and<br />

unregistered on a system. This allows you to<br />

register your class in a component category that<br />

the Customize dialog box will look for.<br />

The ComVisible attribute is set to false to<br />

ensure that this method cannot be called directly<br />

by a COM client. It does not affect the method<br />

being called when the assembly is registered<br />

with COM.<br />

public class Form1 : System.Windows.Forms.Form<br />

{<br />

…<br />

private ITransformEvents_VisibleBoundsUpdatedEventHandler<br />

visBoundsUpdatedE;<br />

private ICustomizeDialog m_CustomizeDialog = new<br />

CustomizeDialogClass(); // The CustomizeDialog used by the<br />

ToolbarControl<br />

private ICustomizeDialogEvents_OnStartDialogEventHandler<br />

startDialogE; // The CustomizeDialog start event<br />

private ICustomizeDialogEvents_OnCloseDialogEventHandler<br />

closeDialogE; // The CustomizeDialog close event<br />

2. Create a new function called CreateCustomizeDialog. This is where you will<br />

create the Customize dialog box by adding the following code to the function:<br />

private void CreateCustomizeDialog()<br />

{<br />

// Set the customize dialog box events.<br />

startDialogE = new<br />

ICustomizeDialogEvents_OnStartDialogEventHandler(OnStartDialog);<br />

((ICustomizeDialogEvents_Event)m_CustomizeDialog).OnStartDialog +=<br />

startDialogE;<br />

closeDialogE = new<br />

ICustomizeDialogEvents_OnCloseDialogEventHandler(OnCloseDialog);<br />

((ICustomizeDialogEvents_Event)m_CustomizeDialog).OnCloseDialog +=<br />

closeDialogE;<br />

// Set the title.<br />

m_CustomizeDialog.DialogTitle = "Customize ToolbarControl Items";<br />

// Show the Add from File button.<br />

m_CustomizeDialog.ShowAddFromFile = true;<br />

// Set the ToolbarControl that new items will be added to.<br />

m_CustomizeDialog.SetDoubleClickDestination(axToolbarControl1);<br />

}<br />

3. Call the CreateCustomizeDialog function from the Form_Load event before<br />

the call to the CreateOverviewSymbol subroutine.<br />

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

{<br />

// Create the Customize dialog box for the ToolbarControl.<br />

CreateCustomizeDialog();<br />

}<br />

// Create symbol used on the MapControl…<br />

352 • <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!