add-in button - mouse down capture?

2560
3
01-14-2011 10:13 AM
helenchu
Occasional Contributor II
All,
I'm trying to built a add-in button which will need to get x,y from a mouse down click.  How do I do it? For example I have Function MouseDownXY so what I need to write on the button Sub Onclick() to make it go to my function?  I'm using vb.net.  Thank you very much for your help.

Function MouseDownXY(ByVal x As Long, ByVal y As Long)
Set pPoint = pMxApp.Display.DisplayTransformation.ToMapPoint(x, y)
End Function
0 Kudos
3 Replies
by Anonymous User
Not applicable
Original User: rwelikal

Well, you can make a TOOL or you can make a command.. a TOOL will initiate the code when you CLICK the map.
I would draw a point on click using the ESRI snippet.

    Public Sub DrawPoint(ByVal activeView As ESRI.ArcGIS.Carto.IActiveView, ByVal x As System.Int32, ByVal y As System.Int32)

        If activeView Is Nothing Then
            Return
        End If

        Dim screenDisplay As ESRI.ArcGIS.Display.IScreenDisplay = activeView.ScreenDisplay

        ' Constant
        screenDisplay.StartDrawing(screenDisplay.hDC, CShort(ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache))
        Dim simpleMarkerSymbol As ESRI.ArcGIS.Display.ISimpleMarkerSymbol = New ESRI.ArcGIS.Display.SimpleMarkerSymbolClass

        Dim symbol As ESRI.ArcGIS.Display.ISymbol = TryCast(simpleMarkerSymbol, ESRI.ArcGIS.Display.ISymbol) ' Dynamic Cast
        screenDisplay.SetSymbol(symbol)
        Dim displayTransformation As ESRI.ArcGIS.Display.IDisplayTransformation = screenDisplay.DisplayTransformation

        ' X and Y are in device coordinates
        Dim point As ESRI.ArcGIS.Geometry.IPoint = displayTransformation.ToMapPoint(x, y)

        screenDisplay.DrawPoint(point)
        screenDisplay.FinishDrawing()

    End Sub


Then I would use another snippet and use that point to get the click location:

    Public Function GetMapCoordinatesFromScreenCoordinates(ByVal screenPoint As ESRI.ArcGIS.Geometry.IPoint, ByVal activeView As ESRI.ArcGIS.Carto.IActiveView) As ESRI.ArcGIS.Geometry.IPoint

        If screenPoint Is Nothing OrElse screenPoint.IsEmpty OrElse activeView Is Nothing Then
            Return Nothing
        End If

        Dim screenDisplay As ESRI.ArcGIS.Display.IScreenDisplay = activeView.ScreenDisplay
        Dim displayTransformation As ESRI.ArcGIS.Display.IDisplayTransformation = screenDisplay.DisplayTransformation

        Return displayTransformation.ToMapPoint(CInt(screenPoint.X), CInt(screenPoint.Y))

    End Function


Hope that helps.
0 Kudos
helenchu
Occasional Contributor II
Thank you very much.  Yes you did help alot just by the word "TOOL"
0 Kudos
by Anonymous User
Not applicable
Original User: ellmenreich

hello,
by using the addins i must choose tool or button. i will convert my 9.3 c# code to addin and will prevent an installer with registrations. so in 9.3 i have a tool wich inherit from basetool. the tool opens a form in the onclick method. in the mouse down events i capture the geometry and send it to the form. the new addins tool did not have a onclick method and the button no onmousedown event.
also i cannot call the tool from the form by setting application.currenttool = addins.tool because of it is no command.
so what is the new way to open a form, select somthing like geometrytype (point or line), enable any kind (drawing or editing) of digitze and get back the new geometry to form.

thanks
0 Kudos