Click here to get the sample associated with this walkthrough.
In this topic
- Creating a project in Visual Studio
- Setting combo box properties
- Populating the combo box
- Adding the rotate note functionality
- Compiling the project
- Using the add-in in ArcGIS Explorer
- Debugging the add-in
Creating a project in Visual Studio
To create a custom combo box project in Visual Studio, perform the following steps:
- 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.
- 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 C# dialog boxes in the screen shots, since the dialog boxes and views you interact with in VB .NET are very similar.
- Click the Visual C# or Visual Basic project node in the Project types pane, click the ArcGIS node, then click the Explorer node.
- Click the ArcGIS Explorer ComboBox template in the Templates pane.
- Name the project RotateNote, then click Browse to locate where you want to save the project. See the following screen shot:
- Click OK to create the project. The New ArcGIS Explorer ComboBox Project dialog box opens where you can set the properties for the combo box.
Setting combo box properties
To set properties for the combo box, perform the following steps:
-
On the Project Settings page of the New ArcGIS Explorer ComboBox 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:
-
Click Next. The ComboBox Settings page of the New ArcGIS Explorer ComboBox Project dialog box opens as shown in the following screen shot:
-
Type a caption, for example, ComboBox Walkthrough in the Caption text box; and type a ToolTip, for example, Choose an amount to rotate the selected polygon note.
-
Change the Availability property to enable the add-in when a note is selected.
-
Change the large and small image to an appropriate icon such as the rotate icon provided in the Images folder of the sample associated with this walkthrough. The sample can be found in your install directory, i.e. Program Files\Explorer\DeveloperKit\Samples\ComboBoxWalkthrough.
-
Leave the Drop-down Rows and Width Size String options blank to accept the defaults for the add-in, and click Finish.
Populating the combo box
To populate the combo box with the pre-determined rotation values, perform the following steps:
- Double-click the ComboBox.cs class in Solution Explorer to view the template code.
- Locate the ComboBox class.
- Insert the following code example:
public ComboBox()
{
//Add rotation options.
ComboItem itm = new ComboItem("45");
itm = new ComboItem("45");
itm.Tag = 45;
this.Items.Add(itm);
itm = new ComboItem("90");
itm.Tag = 90;
this.Items.Add(itm);
itm = new ComboItem("135");
itm.Tag = 135;
this.Items.Add(itm);
itm = new ComboItem("180");
itm.Tag = 180;
this.Items.Add(itm);
itm = new ComboItem("225");
itm.Tag = 225;
this.Items.Add(itm);
itm = new ComboItem("270");
itm.Tag = 270;
this.Items.Add(itm);
itm = new ComboItem("315");
itm.Tag = 315;
this.Items.Add(itm);
}
[VB.NET]
Public Sub New()
'Add rotation options.
Dim itm As New ComboItem("45")
itm = New ComboItem("45")
itm.Tag = 45
Me.Items.Add(itm)
itm = New ComboItem("90")
itm.Tag = 90
Me.Items.Add(itm)
itm = New ComboItem("135")
itm.Tag = 135
Me.Items.Add(itm)
itm = New ComboItem("180")
itm.Tag = 180
Me.Items.Add(itm)
itm = New ComboItem("225")
itm.Tag = 225
Me.Items.Add(itm)
itm = New ComboItem("270")
itm.Tag = 270
Me.Items.Add(itm)
itm = New ComboItem("315")
itm.Tag = 315
Me.Items.Add(itm)
End Sub
Adding the rotate note functionality
To add the rotate note functionality, perform the following steps:
- Double-click the ComboBox.cs class in Solution Explorer to view the template code.
- Locate the OnSelectionChange method in the ComboBox.cs class.
- Insert the following code example:
public override void OnSelectionChange(ComboItem item)
{
if (this.SelectedItem != null)
{
double degrees = Convert.ToDouble(item.Tag);
// Grab the selected note.
SelectedItemsCollection selItems =
ESRI.ArcGISExplorer.Application.Application.SelectedItems;
if ((selItems.Count == 1) && (selItems[0] is Note))
{
Note selected = selItems[0] as Note;
// Rotate the geometry.
Geometry rotated = GeometryOperations.Rotate
(selected.Graphic.Geometry, (degrees * - 1),
Unit.Angular.Degrees);
// Update the geometry of the graphic.
selected.Graphic.Geometry = rotated;
// Reset the selection of the combobox.
this.SelectedItem = null;
}
}
}
[VB.NET]
Public Overrides Sub OnSelectionChange(ByVal Item As ComboItem)
If Me.SelectedItem IsNot Nothing Then
Dim degrees As Double = Convert.ToDouble(Item.Tag)
' Grab the selected note.
Dim selItems As SelectedItemsCollection = ESRI.ArcGISExplorer.Application.Application.SelectedItems
If (selItems.Count = 1) AndAlso (TypeOf selItems(0) Is Note) Then
Dim selected As Note = TryCast(selItems(0), Note)
' Rotate the geometry.
Dim rotated As Geometry = GeometryOperations.Rotate(selected.Graphic.Geometry, (degrees * -1), Unit.Angular.Degrees)
' Update the geometry of the graphic.
selected.Graphic.Geometry = rotated
' Reset the selection of the combobox.
Me.SelectedItem = Nothing
End If
End If
End Sub
When using this add-in, rotation is on the note itself, not on the note graphic. Rotation is visually apparent when using polygon and line notes.
Compiling the project
To build the project, perform the following steps:
- Save the project.
- 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.
- If you successfully followed this walkthrough, the build will succeed and the combo box will be created. Close Visual Studio.
- 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 combo box in ArcGIS Explorer, perform the following steps:
- Start ArcGIS Explorer and add a polygon note.
- Select the note in the contents.
- Click the Add-Ins tab to view the combo box.
- Click the combo box and select a value to rotate the note. Notice that the note rotates by the value you selected in the combo box.
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: Combobox walkthroughHow to debug add-ins in Visual Studio