wilhelm kurz software

home
application notes

dynaplot application notes

cursor click

Activating the cursor when the user clicks into the plot area

Problem

Cursor mode shall be switched on and the cursor shall be placed at the mouse position when the user clicks into the plot area. A click into the chart area shall be ignored.

Solution

Because the MouseDown events gives us the screen coordinates of the mouse in pixels but the cursor coordinates must be in scale units we need transformation functions to obtain the physical coordinates. Each axis provides a method PhysicalCoordinate() which yields a coordinate in scale units for a given screen coordinate.  

Regard the following code:

Private Sub DynaPlot1_MouseDown(Button As Integer, Shift As Integer, X As Long, Y As Long)

  If DynaPlot1.Cursors.Enable.State = False Then
    Dim newX As Double, newY As Double

    ' compute physical coordinates of the mouse position
    newX = DynaPlot1.Axes.XAxis.PhysicalCoordinate(X)
    newY = DynaPlot1.Axes.YAxis.PhysicalCoordinate(Y)

    If newX >= DynaPlot1.Axes.XAxis.From And _
       newX <= DynaPlot1.Axes.XAxis.To And _
       newY >= DynaPlot1.Axes.YAxis.From And _
       newY <= DynaPlot1.Axes.YAxis.To Then

      ' switch the cursor on
      DynaPlot1.Cursors.Enable.State = True

      ' move the cursor to where the mouse is
      DynaPlot1.Cursors.Move newX, newY
    End If
  End If
End Sub

  

[home] [products] [news] [contact] [links]