Using Measure Plugin

Jan 30, 2012 at 3:48 PM

Can someone please give me a hint about how to use the Measure plugin tool which was recently moved out of the base to a plugin? My code looks like this:

    Private Sub mnuToolsMeasure_Click(sender As System.Object, e As System.EventArgs) Handles mnuToolsMeasure.Click
        GISMap.FunctionMode = FunctionMode.None
        GISMap.Cursor = Cursors.Cross
        With New MapFunctionMeasure(GISMap)
            .Activate()
        End With
    End Sub

The dialog appears, but it is not responding to mouse clicks. Do I need to pass those to the plugin myself?

Thanks,

Chris

Developer
Jan 30, 2012 at 10:43 PM

You'll need to add the mapfunction you are creating to the GISMap.MapFunctions list. The constructor makes it look like it would add itself, but it doesn't.

Jan 31, 2012 at 1:59 AM

Mudnug:

Thanks much for your reply. I was able to do as you suggested and modified my code as follows:

    Private WithEvents mf As MapFunctionMeasure

    Private Sub mnuToolsMeasure_Click(sender As System.Object, e As System.EventArgs) Handles mnuToolsMeasure.Click
        With GISMap
            .FunctionMode = FunctionMode.None
            'if was already added, remove and add again (otherwise, displays prior graphic measurements)
            For Each mapfunc As IMapFunction In .MapFunctions
                If TypeOf mapfunc Is MapFunctionMeasure Then
                    .MapFunctions.Remove(mapfunc)
                    Exit For
                End If
            Next
            mf = New MapFunctionMeasure(GISMap)
            .MapFunctions.Add(mf)
            .Cursor = Cursors.Cross
            mf.Activate()
        End With
    End Sub

    Private Sub mf_FunctionDeactivated(sender As Object, e As System.EventArgs) Handles mf.FunctionDeactivated
        'this never fires
    End Sub

Upon mf.Activate, the modeless dialog appears and I am able to measure areas and distances. I need to be able to capture when the dialog is closed though (so I can turn on my context menu again for the map and reset my cursor), and find that the FunctionDeactivated doesn't fire when the form is closed. Is there any other way to find out when the user closes that form?

Also, a couple other nitpicks when you get time:

  • form should not be resizable
  • combobox should have style dropdownlist
  • the startup position should be remembered and restored
  • the name and cursorbitmap properties are Nothing

Thanks,

Chris

Developer
Jan 31, 2012 at 6:10 PM

Hi Chris,

  • I've changed the form style to fixed.
  • The combobox to dropdownlist
  • The start position was windows default position (must not save the position)
  • The name of the dialog is MeasureDialog, so I'm not sure what you mean there.
  • I also noticed it was displaying the wrong units at startup and fixed that.

Thanks for your suggestions!

As for capturing that form (and wiring an event to FormOnClosing) it seems VB has a special collection that might help: http://msdn.microsoft.com/en-us/library/eh13dca9.aspx

Jan 31, 2012 at 8:36 PM

Thanks for the fixes.

FYI, my comment about Name and CursorBitmap referred to the MapFunctionMeasure class. I don't know enough about the plugin architecture to even know if those properties are used in general (but it would be nice to expose them).

I will look into tracking the form being closed using OpenForms a you suggest.

Thanks,

Chris

Developer
Feb 1, 2012 at 4:15 PM

I've added in a name. I don't think we need to set a CursorBitmap, though, as we use the default Cross cursor.

Apr 13, 2012 at 3:56 PM

Could really do with a method to allow the dialog to be closed without having to parse through open windows and force a close that way and well as an exposed event for the _measureDialog.FormClosed event


Jul 16, 2013 at 12:28 AM
Code above worked for me thx.....
Aug 10, 2014 at 8:01 AM
How source code measure for measure tool in VB.NET?

Thanks everyone