Creating a Custom CheckBox


Summary
This walkthrough shows how to create a custom check box for ArcGIS Explorer. The easiest way to create a check box is to use the templates provided with the software development kit (SDK).

Click here to get the sample associated with this walkthrough.

In this topic


Creating a project in Visual Studio

To create a custom check box project in Visual Studio, perform the following steps: 
  1. Start Visual Studio.
While this topic refers to and shows screen shots from Visual Studio 2008 running on Windows Vista, you can also follow the steps in Visual Studio 2010, Visual Basic Express, and Visual C# Express, in Windows XP or Windows 7.
  1. Click File, click New, and click New Project. The New Project dialog box opens.
To complete this walkthrough, you can use C# or VB .NET. The code for both is shown; however, this topic only shows the VB .NET dialog boxes in the screen shots, since the dialog boxes and views you interact with in C# are very similar.
  1. Click the Visual C# or Visual Basic project node in the Project types pane, click the ArcGIS node, then click the Explorer node.
  2. Click the ArcGIS Explorer CheckBox template in the Templates pane.
  3. Name the project TurnImageOverlayOnOff, then click Browse to locate where you want to save the project. See the following screen shot:


  4. Click OK to create the project. The New ArcGIS Explorer CheckBox Project dialog box opens where you can set the properties for the check box.

Setting check box properties

To set properties for the check box, perform the following steps:
  1. On the Project Settings page of the New ArcGIS Explorer CheckBox Project dialog box, the Display Name property is automatically added. Fill in the Description, Group Caption (displays on the Add-Ins tab), and Publisher text boxes as appropriate. See the following screen shot:


  1. Click Next. The CheckBox Settings page of the New ArcGIS Explorer CheckBox Project dialog box opens as shown in the following screen shot:


  1. Type a caption, for example, CheckBox Walkthrough in the Caption text box; and type a ToolTip, for example, Toggle the selected image overlay on and off.
  2. Change the Availability property to enable the add-in when an image overlay is selected.
  3. Click Finish.

Adding the toggle image overlay functionality

To add the toggle image overlay functionality, perform the following steps:
  1. Double-click the CheckBox.cs class in Solution Explorer to view the template code.
  2. Locate the OnClick method in the CheckBox.cs class.
  3. Insert the following code example:
[C#]
// grab the selected Image Overlay & change the state of the ImageOverlay
ImageOverlay selected =
    ESRI.ArcGISExplorer.Application.Application.SelectedItems.GetFirst()as
    ImageOverlay;
if (selected != null)
    selected.Visible = this.Checked;
[VB.NET]
' grab the selected Image Overlay & change the state of the ImageOverlay
Dim selected As ImageOverlay = TryCast(ESRI.ArcGISExplorer.Application.Application.SelectedItems.GetFirst(), ImageOverlay)
If selected IsNot Nothing Then
    selected.Visible = Me.Checked
End If
  1. Locate the OnUpdate method in the CheckBox.cs class.
  2. Insert the following code example to change the state of the checkbox to match the state of the Image Overlay in the Contents.
[C#]
// grab the selected Image Overlay & change the state of the checkbox to match 
ImageOverlay selected =
    ESRI.ArcGISExplorer.Application.Application.SelectedItems.GetFirst()as
    ImageOverlay;
if (selected != null)
{
    this.Enabled = true;
    this.Checked = selected.Visible;
}

else
    this.Enabled = false;
[VB.NET]
' grab the selected Image Overlay & change the state of the checkbox to match
Dim selected As ImageOverlay = TryCast(ESRI.ArcGISExplorer.Application.Application.SelectedItems.GetFirst(), ImageOverlay)
If selected IsNot Nothing Then
    Me.Enabled = True
    Me.Checked = selected.Visible
Else
    Me.Enabled = False
End If

Compiling the project

To build the project, perform the following steps:
  1. Save the project.
  2. Click the Build menu and click Build Solution. If the project built correctly, a report stating that the build succeeded appears in the Output window at the bottom of the Visual Studio .NET integrated development environment (IDE).
You can also check the results of the build operation by reviewing the subdirectories of the project. By default, a debug version of the project is built. The dynamic-link library (DLL) that results from the build operation is stored in the Bin\Debug subdirectory of the project. This directory also contains debug information (.pdb) and a type library (.tlb) file produced by the Assembly Registration tool.
The obj subdirectory of the project directory contains temporary files used by the compiler and Visual Studio.
  1. If you successfully followed this walkthrough, the build will succeed and the check box will be created. Close Visual Studio.
  2. If the build operation did not succeed, click View, and click Task List to view the errors, correct the errors as indicated, then close Visual Studio when you have a successful build.
If you double-click the task, the line of code causing the error is automatically selected.
On a successful build, the necessary files are automatically added to the following locations:
  • For Windows Vista and Windows 7—C:\Users\<username>\AppData\Roaming\ESRI\ArcGIS Explorer\Addins.
  • For Windows XP—C:\Documents and Settings\<username>\Application Data\ESRI\ArcGIS Explorer\AddIns.

Using the add-in in ArcGIS Explorer

To use the new check box in ArcGIS Explorer, perform the following steps:
  1. Start ArcGIS Explorer and add an image overlay.
  2. Select the image overlay in the contents.
  3. Click the Add-Ins tab to view the check box.
  4. Click the check box and notice that the image overlay is on.
  5. Click the image overlay again and notice that the image overlay turns off.

Debugging the add-in

Running the add-in in debug mode allows you to step through the code when it is executed. This is helpful when you encounter bugs in custom add-ins. If you followed the steps in this topic, you should not have to debug the add-in you created.
For more information about debugging add-ins, see How to debug add-ins in Visual Studio.


See Also:

Sample: Checkbox walkthrough
How to debug add-ins in Visual Studio