The Microsoft MapPoint Control 9.0 is an ActiveX control that is included with Microsoft MapPoint 2002. This control provides a convenient way to implement MapPoint 2002 functionality on a form in a Visual C# .NET project. By using this control, you can access most, but not all, MapPoint 2002 functionality. For example, you cannot programmatically save a map in the HTML format with the ActiveX control, but you can save the map as a MapPoint .ptm file by using the control, and then programmatically open the .ptm file in MapPoint and save it as HTML. This article contains sample code that demonstrates this solution.
The MapPoint 9 Control installs its own type library and a version of the MapPoint 2002 type library, but not all of the latter. For this example, you need the complete MapPoint 2002 type library as well as the partial type library that ships with the control to build an instance of the Application object. The type library for MapPoint 2002 has a namespace attribute that conflicts with the namespace of the version that is supplied (imported) by the control; when you import the MapPoint 2002 type library, you can use a different namespace to avoid this conflict.
Import the MapPoint Type Library
From the Programs list on the Start menu, click Microsoft Visual Studio .NET, click Visual Studio .NET Tools, and then click Visual Studio .NET CommandPrompt.
NOTE: The default folder for Mpna81.tlb is C:\Program Files\Microsoft Mappoint.
Create the Sample Project
Start Microsoft Visual Studio .NET. On the File menu, click New and then click Project. Under Project types click Visual C# Projects, then click Windows Application under Templates.
In the New Project dialog box, type MappointControl for the project name and then click OK. Form1 is created by default.
On the Project menu, click Add Reference. In the Add Reference dialog box, click Browse. Select C:\MapPointApp.dll and then click Open. Click OK to dismiss the Add Reference dialog box.
On the Tools menu, click Customize Toolbox.
In the list of COM components, click Microsoft MappointControl 9 and then click OK.
Press CTRL+ALT+X to display the Toolbox.
Draw a MapPoint control and three Button controls on Form1.
NOTE: The MapPoint control is added to the bottom of the toolbox and is identified by a MapPoint pushpin icon and the text "Control".
Set the Text properties of Button1, Button2, and Button3 to Make Route Map, Save Map As HTML, and Close the Project, respectively.
Add event handlers for the form Load event and the Click events of the buttons. To do this, follow these steps:
In Design view for Form1.cs, double-click Form1. The event handler is created and displayed in the Form1.cs code window.
On the View menu, click Designer to switch to Design view.
Repeat steps a and b for each of the three button controls.
NOTE: If you did not install MapPoint to the default installation folder, modify the value of objTemplate in Form1_Load so that the path to the template matches your installation of MapPoint.
Test the Sample
Press F5 to build and run the program. Form1 loads with a map of North America.
Click Make Route Map. MapPoint draws a route map from a starting point, through a midpoint, through another midpoint, and back to the endpoint (which is the same as the starting point). The timed itinerary appears in a list box above the map. A copy of the displayed map is saved as C:\Atestmap.ptm.
Click Save Map as HTML. On your hard drive, you now see the C:\Atestmap.htm file. Double-click the file to see your route map in your Web browser.
Click Close the Project to dispose of Form1 and the map.