Hi
I want to be able to force the drawline to remain horizontal, if for example the user is holding down a specific key while drawing. I tried the following line of code in the OnDrawLineToolLineDrag event:
Chart1.Tools.Items(Chart1.Tools.Count - 1).asDrawLine.ToPoint.Y = Chart1.Tools.Items(Chart1.Tools.Count - 1).asDrawLine.FromPoint.Y
It's a bit 'messy' though. Is there some way to do this?
Thanks
Horizontal Drawline
Hi Rossmc,
It wasn't as easy as seemed. I tested using different events and always appeared both normal line and horizontal line while drawing. And trying to solve this, I tried to deactivate the tool, but then the old lines disappeared too.
So, the best way I can think to do this is to draw directly to the canvas the temporal line and add the line to the tool in OnMouseUp event. Note that I use KeyCode 16 (Left Shift key) to enable "horizontal forcing". And also note that I use OnMouseDown event to store the origin of the line in xx and yy variables. And I use OnMouseMove event to draw the temporal line I mentioned above.
It wasn't as easy as seemed. I tested using different events and always appeared both normal line and horizontal line while drawing. And trying to solve this, I tried to deactivate the tool, but then the old lines disappeared too.
So, the best way I can think to do this is to draw directly to the canvas the temporal line and add the line to the tool in OnMouseUp event. Note that I use KeyCode 16 (Left Shift key) to enable "horizontal forcing". And also note that I use OnMouseDown event to store the origin of the line in xx and yy variables. And I use OnMouseMove event to draw the temporal line I mentioned above.
Code: Select all
Dim KeyActivation, LineDrawing As Boolean
Dim xx, yy As Integer
Private Sub Form_Load()
TeeCommander1.Chart = TChart1
KeyActivation = False
LineDrawing = False
TChart1.Tools.Items(0).asDrawLine.EnableDraw = False
TChart1.Zoom.Enable = False
End Sub
Private Sub TChart1_OnKeyDown(ByVal KeyCode As Long, ByVal Shift As TeeChart.EShiftState)
If KeyCode = 16 Then
KeyActivation = True
End If
End Sub
Private Sub TChart1_OnKeyUp(ByVal KeyCode As Long, ByVal Shift As TeeChart.EShiftState)
If KeyCode = 16 Then
KeyActivation = False
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)
xx = X
yy = Y
If TChart1.Tools.Items(0).asDrawLine.Clicked(X, Y) < 0 Then
LineDrawing = True
End If
End Sub
Private Sub TChart1_OnMouseMove(ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
If LineDrawing Then
TChart1.Repaint
If KeyActivation Then
TChart1.Canvas.DrawLine xx, yy, X, yy
Else
TChart1.Canvas.DrawLine xx, yy, X, Y
End If
End If
End Sub
Private Sub TChart1_OnMouseUp(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
If LineDrawing Then
If KeyActivation Then
TChart1.Tools.Items(0).asDrawLine.AddLine TChart1.Axis.Bottom.CalcPosPoint(xx), _
TChart1.Axis.Left.CalcPosPoint(yy), _
TChart1.Axis.Bottom.CalcPosPoint(X), _
TChart1.Axis.Left.CalcPosPoint(yy)
Else
TChart1.Tools.Items(0).asDrawLine.AddLine TChart1.Axis.Bottom.CalcPosPoint(xx), _
TChart1.Axis.Left.CalcPosPoint(yy), _
TChart1.Axis.Bottom.CalcPosPoint(X), _
TChart1.Axis.Left.CalcPosPoint(Y)
End If
LineDrawing = False
End If
End Sub
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |