View Full Version : How to put Mappoint into drawing mode (rectangle/poly) programmatically

10-25-2012, 09:48 AM
I don't want to display the Mappoint toolbars for various reasons, but I need to give my users the ability to select pushpins via rectangle or polyline. Is there a way to do that programmatically?

A related question - is there a way to control the drawing of a polyline such that it is always closed? By that I mean that the user clicks on the first point and draws the line to the second point (obviously generating just a line). However, when he draws from the second point to the third, I want to automatically attach that third vertex to the first (creating a triangle). If they draw to a fourth point, I want the fourth point connected to the first (creating a 4-sided polygon), and so forth.

My objective is to allow the user to select a range of pushpins without having to draw back to the first point and double click to complete the closed polygon.


Bob M..

Eric Frost
10-25-2012, 11:13 AM
>> put Mappoint into drawing mode (rectangle/poly) programmatically <<

This is possible but it's not easy.. I've done it in an application, but it was a couple years ago already. See these articles --

Extending the MapPoint ActiveX Control - Pt. I - MapPoint Articles - MP2K Magazine (http://www.mp2kmag.com/a88--ActiveX.MapPoint.extend.mappoint.html)
Extending the MapPoint ActiveX Control - Pt. II - MapPoint Articles - MP2K Magazine (http://www.mp2kmag.com/a96--ActiveX.Extending.Spy.mappoint.html)

I think I may have also used another article or reference, but I'm not sure what now.

Let us know how it goes and if you make any progress.

Note that you don't need to close the Shape in order to do a query, you can get the vertices and then use QueryPolygon and pass in the Vertices, so it doesn't matter if the actual Shape on the map is closed or not.


01-14-2013, 03:46 PM
Eric -

We have been able to implement almost everything else that we need except for this drawing mode (and perhaps the ability to stop map updates while plotting a large number of stops).

Do you have any further info on how to implement the selection mode type? I've played with Spy++ until my eyes bleed, but there does not seem to be a WM_COMMAND associated with that button press. The closest I've been able to track it is the WM_MOUSEACTIVATE.

I know this can be done as I've seen at least one other application that was able to implement their own UI for setting the selection mode. This is the last thing I need to remove all mappoint toolbars from my application, so I'll keep digging myself.

Thanks for any help.

09-20-2013, 07:13 AM
Well, here's how I added shapes (rectangles) on the map via c#.

First I put a menu item called Add Shape.
private void addShapeToolStripMenuItem_Click(object sender, EventArgs e)
doingShape = 1;
addShapeToolStripMenuItem.Checked = true;

Then in the MapPoint MouseDown event I added:

private void MPC_MouseDownEvent(object sender, AxMapPoint._IMappointCtrlEvents_MouseDownEvent e)
if (doingShape > 0)
if (doingShape == 1)
// capture first point (upper Left) of the rectangle
MapPoint.Location objLoc = null;
object key = 1;
objLoc = MPC.ActiveMap.XYToLocation(e.x, e.y);
MPC.ActiveMap.Application.Units = MapPoint.GeoUnits.geoMiles;
MapPoint.Shape myShp1 = MPC.ActiveMap.Shapes.AddShape(MapPoint.GeoAutoShap eType.geoShapeRectangle, objLoc, 5, 5);
myShp1.Line.Weight = 1;
myShp1.Line.ForeColor = System.Drawing.ColorTranslator.ToOle(System.Drawin g.Color.Green);
myShp1.Name = "S1";
doingShape = 0;// 2;

That puts a square with the upper left positioned on the click. Click on the square, and you can grab the handles to strech it into any shape you want. You don't have to worry abou the user properly closing the the polygon.

From there, it's a simple matter to query the contents of the shape (S1).

Hope that helps,