Hi!
I've placed Select Case code in TChart1_OnRectangleToolDragging().
When the Retangle Tool is clicked on, how do I get the index of the Rectangle that has been selected?
In otherwords; How do I know which Rectangle the user has clicked on (and is now dragging)?
Thanks
Getting the Index of the Retangle Tool selected
Re: Getting the Index of the Retangle Tool selected
Hello,
Between OnRectangleToolClick, OnRectangleToolDragging, and XY checking code, I was able to derive an index. This method is not terribly reliable, so I would still like a cleaner solution if there is one available!
Thanks
Between OnRectangleToolClick, OnRectangleToolDragging, and XY checking code, I was able to derive an index. This method is not terribly reliable, so I would still like a cleaner solution if there is one available!
Thanks
Re: Getting the Index of the Retangle Tool selected
Ok, so this really isn't working well at all.
Please tell me there is an easy method of obtaining the ToolNumberIndex from a Rectangle that has been clicked!
Thanks!
Please tell me there is an easy method of obtaining the ToolNumberIndex from a Rectangle that has been clicked!
Thanks!
Re: Getting the Index of the Retangle Tool selected
Hi tirby,
This simple example seems to work fine for me here:
If you still find problems with it, please try to arrange a simple example project we can run as-is to reproduce the problem here. This usually helps customers to find a fix for themselves.
This simple example seems to work fine for me here:
Code: Select all
Private Sub Form_Load()
TeeCommander1.ChartLink = TChart1.ChartLink
'TChart1.Header.Text.Text = TChart1.Version
Dim XValue, YValue As Double
Dim XPos, YPos, tmpHeight As Integer
Dim rect, dline As Long
TChart1.Aspect.View3D = False
TChart1.AddSeries scPoint
TChart1.Series(0).FillSampleValues 10
TChart1.Environment.InternalRepaint
Dim i As Integer
For i = 0 To TChart1.Series(0).Count - 1
XPos = TChart1.Series(0).CalcXPos(i)
YPos = TChart1.Series(0).CalcYPos(i)
XValue = TChart1.Series(0).XValues.Value(i)
YValue = TChart1.Series(0).YValues.Value(i)
rect = TChart1.Tools.Add(tcRectangle)
dline = TChart1.Tools.Add(tcDrawLine)
With TChart1.Tools.Items(rect).asRectangle
.Text = "Point " + Str$(i)
.AutoSize = True
tmpHeight = .Bounds.Bottom - .Bounds.Top
.Left = XPos - (TChart1.Canvas.TextWidth(.Text) / 2)
.Top = YPos - 10 - tmpHeight
End With
With TChart1.Tools.Items(dline).asDrawLine
.EnableDraw = False
.EnableSelect = False
.AddLine XValue, YValue, XValue, TChart1.Axis.Left.CalcPosPoint(YPos - 10)
End With
Next i
End Sub
Private Sub TChart1_OnRectangleToolClick(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
Dim i As Integer
Dim clickedRect As Long
clickedRect = -1
For i = 0 To TChart1.Tools.Count - 1
If TChart1.Tools.Items(i).ToolType = tcRectangle And TChart1.Tools.Items(i).asRectangle.Clicked(X, Y) Then
clickedRect = i
Exit For
End If
Next i
If clickedRect > -1 Then
MsgBox "Rectangle clicked. Tool index: " + Str$(clickedRect)
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 |
Re: Getting the Index of the Retangle Tool selected
Ok, I'm finally back on this project!
The problem with the code that Yeray posted on 21-Mar, is that it does not allow for a situation where multiple rectangles are stacked on top of one another.
If rectangle #2 is placed over rectangle #1, partially covering rectangle #1, then when the user clicks on rectangle #2 in the area where rectangle #1 is directly beneath rectangle #2, the routine will find the cursor within the bounds of rectangle #1 and return the index for rectangle #1.
How can I get this to work correctly?
These tools really need some sort of index property.
The problem with the code that Yeray posted on 21-Mar, is that it does not allow for a situation where multiple rectangles are stacked on top of one another.
If rectangle #2 is placed over rectangle #1, partially covering rectangle #1, then when the user clicks on rectangle #2 in the area where rectangle #1 is directly beneath rectangle #2, the routine will find the cursor within the bounds of rectangle #1 and return the index for rectangle #1.
How can I get this to work correctly?
These tools really need some sort of index property.
Re: Getting the Index of the Retangle Tool selected
Hello,
So, you are who has to decide what to return in these cases. How? We are looping from index 0 to Count-1 in OnRectangleToolClick event. That's why we get the first tool that is being clicked. If you want the second, you can loop reverse, from Count-1 to 0.
Correct here is something quite subjective. I mean, having two rectangles superposed, and clicking in the region shared by both rectangles, both answers would be correct because actually both rectangles are under the mouse when the click if made.tirby wrote:How can I get this to work correctly?
So, you are who has to decide what to return in these cases. How? We are looping from index 0 to Count-1 in OnRectangleToolClick event. That's why we get the first tool that is being clicked. If you want the second, you can loop reverse, from Count-1 to 0.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Getting the Index of the Retangle Tool selected
Point taken.
Thanks Yeray!
Thanks Yeray!