我添加了包含图像的矩形工具。我要开发的功能是右键单击我想更改其中的图像。
我尝试使用OnRectangleToolClick但无法获取已单击的矩形工具详细信息。
有人可以帮助我。
由于 阿克沙伊
答案 0 :(得分:1)
我用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
以上似乎不能正常工作,但在调试后我看到当我用鼠标右键点击矩形工具并触发TChart1_OnRectangleToolClick
时,Button
变量具有值为1,而mbRight
为2.因此更改它会使其工作:
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
修改强>:
如果要检查用户何时用鼠标左键单击矩形工具,OnRectangleToolClick
事件可能会与拖动功能发生冲突。
在这种情况下,您仍然可以使用OnMouseMove
,OnClick
和OnMouseDown
个事件,如下例所示:
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