0
votes

I have added rectangle tool which contain an Image. The feature I want to develop is on right Click I want to change the image in it.

I tried using OnRectangleToolClick but not able to get the rectangle tool details which has been clicked.

Can someone help me with this.

Thanks Akshay

1

1 Answers

1
votes

I've made a simple example with VB6:

Private Sub Form_Load()      
  TChart1.AddSeries scBar
  TChart1.Series(0).FillSampleValues 8

  TChart1.Tools.Add tcRectangle
  TChart1.Tools.Items(0).asRectangle.Shape.Picture.LoadImage "C:\tmp\MyImage.jpg"
End Sub

Private Sub TChart1_OnRectangleToolClick(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
  If Button = mbRight Then
    MsgBox "Rectangle clicked with the right mouse button"
  End If
End Sub

The above seems not to work fine, but after debugging I've seen when I click on the rectangle tool with the right mouse button and TChart1_OnRectangleToolClick is fired, the Button variable has the value 1, while mbRight is 2. So changing it for this makes it work:

Private Sub TChart1_OnRectangleToolClick(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
  If Button = 1 Then
    MsgBox "Rectangle clicked with the right mouse button"
  End If
End Sub

EDIT:

If you want to check when the user clicks the Rectangle tool with the left mouse button, the OnRectangleToolClick event may conflict with the dragging feature.
In that case, you could still play with OnMouseMove, OnClick and OnMouseDown events as in the following example:

Dim mouseXPos, mouseYPos, mouseXDown, mouseYDown As Long

Private Sub Form_Load()      
  TChart1.AddSeries scBar
  TChart1.Series(0).FillSampleValues 8

  TChart1.Tools.Add tcRectangle
  TChart1.Tools.Items(0).asRectangle.Shape.Picture.LoadImage "C:\tmp\MyImage.jpg"

  mouseXPos = -1
  mouseYPos = -1
  mouseXDown = -1
  mouseYDown = -1
End Sub

Private Sub TChart1_OnMouseMove(ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
  mouseXPos = X
  mouseYPos = Y
End Sub

Private Sub TChart1_OnClick()
  If mouseXDown = mouseXPos And mouseYDown = mouseYPos Then
    If TChart1.Tools.Items(0).asRectangle.Clicked(mouseXPos, mouseYPos) Then
      MsgBox "Rectangle clicked with the left mouse button"
    End If
  End If
End Sub

Private Sub TChart1_OnMouseDown(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
  mouseXDown = X
  mouseYDown = Y
End Sub