the form below creates a trendline on "Add Line" button pressing. Then it creates second line which extends the first one. When an user selects the extention line it tries to switch to first (main) line since the latter should be used to handle dragging for both lines.
Firstly, the second line is invisible until the chart is refreshed.
Secondly, switching selection doesn't work
Could you give me a workaround to emulate the needed behavior?
nefis
Code: Select all
VERSION 5.00
Object = "{54294AC6-FA71-4C7F-B67C-6C6405DFFD48}#1.0#0"; "TeeChart6.ocx"
Begin VB.Form Form1
BorderStyle = 3 'Fixed Dialog
Caption = "Form1"
ClientHeight = 9705
ClientLeft = 1590
ClientTop = 495
ClientWidth = 13725
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 9705
ScaleWidth = 13725
ShowInTaskbar = 0 'False
Begin TeeChart.TChart TChart1
Height = 9180
Left = 0
TabIndex = 0
Top = 0
Width = 13710
Base64 = $"Form1.frx":0000
End
Begin VB.CommandButton Command1
Caption = "Add Line"
Height = 375
Left = 12480
TabIndex = 1
Top = 9300
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim Xd As Double
Dim Yd As Double
Private Sub Command1_Click()
Dim lt As TeeChart.IDrawLineTool
Dim L As Long
Dim L2 As Long
If Xd = 0 Then
Xd = TChart1.Axis.Bottom.Maximum - TChart1.Axis.Bottom.Minimum
End If
If Yd = 0 Then
Yd = TChart1.Axis.Left.Maximum - TChart1.Axis.Left.Minimum
End If
Set lt = TChart1.Tools.Items(TChart1.Tools.Add(tcDrawLine)).asDrawLine
With lt
L = .AddLine(0, 0, 1, 1)
lt.Lines.Items(L).StartPos.X = TChart1.Axis.Bottom.Minimum + Rnd * Xd
lt.Lines.Items(L).StartPos.Y = TChart1.Axis.Right.Minimum + Rnd * Yd
lt.Lines.Items(L).EndPos.X = TChart1.Axis.Bottom.Minimum + Rnd * Xd
lt.Lines.Items(L).EndPos.Y = TChart1.Axis.Right.Minimum + Rnd * Yd
L2 = .AddLine(0, 0, 1, 1)
lt.Lines.Items(L2).StartPos.X = lt.Lines.Items(L).EndPos.X
lt.Lines.Items(L2).StartPos.Y = lt.Lines.Items(L).EndPos.Y
lt.Lines.Items(L2).EndPos.X = lt.Lines.Items(L).EndPos.X + 10 * (lt.Lines.Items(L).EndPos.X - lt.Lines.Items(L).StartPos.X)
lt.Lines.Items(L2).EndPos.Y = lt.Lines.Items(L).EndPos.Y + 10 * (lt.Lines.Items(L).EndPos.Y - lt.Lines.Items(L).StartPos.Y)
lt.EnableDraw = False
End With
End Sub
Private Sub Form_Load()
Dim i As Long
TChart1.Aspect.View3D = False
TChart1.Legend.Visible = False
Call TChart1.AddSeries(scCandle)
Call TChart1.Series(0).FillSampleValues(100)
TChart1.Series(0).VerticalAxis = aBothVertAxis
TChart1.Axis.Left.Labels.Visible = False
End Sub
Private Sub TChart1_OnDrawLineToolSelectLine()
Dim i As Long
For i = 0 To TChart1.Tools.Count - 1
If TChart1.Tools.Items(i).ToolType = tcDrawLine Then
If TChart1.Tools.Items(i).asDrawLine.Selected <> -1 Then
TChart1.Tools.Items(i).asDrawLine.Selected = 0
End If
End If
Next i
Call TChart1.Repaint
End Sub