There is no direct support for this in the graph. The thing that's tricky about this at the graph level is how would you select the cursor that you want to move if you had multiple cursors in the graph?
Assuming that you only have one cursor, the code snippet below will move the cursor left and right by one point by pressing the left or right arrow keys. To run this example, create a new project in VB6, add a graph to the form, and then paste this code:
Private Const NumberOfPoints = 50
Private Const LeftArrowKeyCode = 37
Private Const RightArrowKeyCode = 39
Private Sub CWGraph1_KeyUp(KeyCode As Integer, Shift As Integer)
If CWGraph1.Cursors.Count > 0 Then
Dim cursor As CWCursor
Set cursor = CWGraph1.Cursors.Item(1)
If KeyCode = LeftArrowKeyCode Then
If cursor.PointIndex > 0 Then
cursor.PointIndex = cursor.PointIndex - 1
End If
ElseIf KeyCode = RightArrowKeyCode Then
If cursor.PointIndex < NumberOfPoints - 1 Then
cursor.PointIndex = cursor.PointIndex + 1
End If
End If
End If
End Sub
Private Sub Form_Load()
PlotSampleData
InitializeGraphCursor
End Sub
Private Sub PlotSampleData()
Dim data(NumberOfPoints - 1) As Double
Dim i As Integer
For i = 0 To NumberOfPoints - 1
data(i) = Rnd() * 10
Next
CWGraph1.PlotY data
End Sub
Private Sub InitializeGraphCursor()
Dim cursor As CWCursor
Set cursor = CWGraph1.Cursors.Add
Set cursor.Plot = CWGraph1.Plots.Item(1)
cursor.PointIndex = CInt(NumberOfPoints / 2)
cursor.SnapMode = cwCSnapAnchoredToPoint
End Sub
Hope this helps in getting you starte
d.
- Elton