Page 1 of 1

Obtaining Index of Rectangle Array

Posted: Fri Nov 05, 2010 8:42 pm
by 9524540
Hello,

I'm using VS2008 VB.Net
I can create multiple Rectangles within the Click event of a push button.
I can also capture a Click event from a mouse click on any of the newly created Rectangles.
My question is , how do I determine the Index of each Rectangle, assuming I have created them as members of an array?

Thanks !!

Re: Obtaining Index of Rectangle Array

Posted: Mon Nov 08, 2010 10:03 am
by narcis
Hi tirby,

We would need more detailed information about your application. Could you please attach a simple example project we can run "as-is" to reproduce the problem here so that we can provide an accurate answer?

Thanks in advance.

Re: Obtaining Index of Rectangle Array

Posted: Mon Nov 08, 2010 4:49 pm
by 9524540
After entering new text in the Textbox, click the "Enter" button.
This will create a rectangle rect(x). Move it to the middle of the graph.
Now change the text in the Textbox and hit the "Enter" button again. A new rectangle wil be created rect(x+1).
Move it to an emplty spot on the graph.
Now monitoring the right label (Label2), click on one of the retangles.
I need to be able to detect in a code module named "rectangle_Click" an index of the retangle that has been clicked.

Re: Obtaining Index of Rectangle Array

Posted: Tue Nov 09, 2010 9:39 am
by narcis
Hi tirby,

Thanks for the project but the "My Project" folder is missing so I can not build the application. Could you please send the project with this folder too?

Thanks in advance.

Re: Obtaining Index of Rectangle Array

Posted: Tue Nov 09, 2010 3:10 pm
by 9524540
Sorry about that,

Here is a Zip file with the files that belong in MyProject!

Thanks

Re: Obtaining Index of Rectangle Array

Posted: Tue Nov 09, 2010 3:38 pm
by narcis
Hi tirby,

Thanks for the files. You just need to do some little modifications in rectangle_Click:

Code: Select all

  Private Sub rectangle_Click(ByVal sender As Object, ByVal e As MouseEventArgs)
    Dim rect As Steema.TeeChart.Tools.RectangleTool = CType(sender, Steema.TeeChart.Tools.RectangleTool)
    Dim c As Integer = TChart1.Tools.IndexOf(rect)
    Dim b As String = "Rectangle " + (c + 1).ToString()

    Label2.Text = b
  End Sub

Re: Obtaining Index of Rectangle Array

Posted: Tue Nov 09, 2010 10:59 pm
by 9524540
Thanks Narcis,

I have modified the routine as such:

Code: Select all

Private Sub rectangle_Click(ByVal sender As Object, ByVal e As MouseEventArgs)
        Dim recti As Steema.TeeChart.Tools.RectangleTool = CType(sender, Steema.TeeChart.Tools.RectangleTool)
        Dim c As Integer = TChart1.Tools.IndexOf(recti)
        Dim b As String = ""
        
        Select Case e.Button
            Case 1048576    'Left
                b = Str(c)
            Case 4194304    'Middle
                b = "Middle"
            Case 2097152    'Right
                rect(c).Dispose()
        End Select

        Label2.Text = b
    End Sub
Now, if you create 2 new rectangles, then right-mouse click on the 1st rectangle (Index 0) created to delete it , the second retangle (Index 1) seems to shift down to Index 0.
However, it won't delete.

Also, is there a background color option available for the rectangles?

Thanks

Re: Obtaining Index of Rectangle Array

Posted: Wed Nov 10, 2010 9:48 am
by narcis
Hi tirby,
Now, if you create 2 new rectangles, then right-mouse click on the 1st rectangle (Index 0) created to delete it , the second retangle (Index 1) seems to shift down to Index 0.
However, it won't delete.
I'm not able to reproduce this here using latest TeeChart for .NET v3 release available at the client area, which is build 3.5.3700.30574/5. Which is the exact TeeChart version you are using? Does last version solves the problems at your end? If it doesn't could you please post the exact steps we should follow to reproduce the problem here?

Also, what about using this?

Code: Select all

        TChart1.Tools.Remove(recti)
or

Code: Select all

        recti.Dispose()
Also, is there a background color option available for the rectangles?
Yes, you can do this:

Code: Select all

    rect(rectcount).Shape.Brush.Color = Color.Red
Thanks in advance.

Re: Obtaining Index of Rectangle Array

Posted: Wed Nov 10, 2010 7:00 pm
by 9524540
I was using version 3.5.3371.26406
I upgraded to version 3.5.3700.30575

This made no difference, the problem still persists.

Using: TChart1.Tools.Remove(recti) works in this instance.
The fact that the Index shifts seems inconsequential at this point.
However, below is a series of steps to re-produce the effect.

1. Create 2 new rectangles.
2. Left-Mouse click on the first retangle, Note the value shown in label2. (displays "0")
3. Left-Mouse click the second retangle, again note the value displayed in Label2. (displays "1")
4. Right-mouse click on the 1st rectangle (Index 0) created to delete it.
5. Left-Mouse click on the remaining rectangle (This should be the second retangle created) The value displayed in Label2 now display's "0"

Re: Obtaining Index of Rectangle Array

Posted: Thu Nov 11, 2010 11:29 am
by narcis
Hi tirby,

Yes, of course, that's because when removing one tool in TChart's tool collection remaining tools indexes are relocated they will always go from 0 to Tools.Count-1. So, if you have to tools (0 and 1) and remove tool with index=0 then tool with index=1 will be re-indexed to 0. If you want to get something which remains through tools re-indexing you can display Tag property, for example:

Code: Select all

  Private Sub rectangle_Click(ByVal sender As Object, ByVal e As MouseEventArgs)
    Dim recti As Steema.TeeChart.Tools.RectangleTool = CType(sender, Steema.TeeChart.Tools.RectangleTool)
    'Dim c As Integer = TChart1.Tools.IndexOf(recti)
    Dim b As String = ""


    Select Case e.Button
      Case MouseButtons.Left
        b = recti.Tag 'Str(c)
      Case MouseButtons.Middle
        b = "Middle"
        recti.Shape.Brush.Color = Color.Red
      Case MouseButtons.Right
        'rect(c).Dispose()
        TChart1.Tools.Remove(recti)
    End Select

    Label2.Text = b

  End Sub

Re: Obtaining Index of Rectangle Array

Posted: Thu Nov 11, 2010 4:55 pm
by 9524540
Thanks for all your help Narcis.

One last question:

How do I change the color of the text in the retangle tool?

Thanks!

Re: Obtaining Index of Rectangle Array

Posted: Fri Nov 12, 2010 8:17 am
by narcis
Hi tirby,

Like this:

Code: Select all

    rect(rectcount).Shape.Font.Color = Color.Red