Obtaining Index of Rectangle Array

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
tirby
Newbie
Newbie
Posts: 16
Joined: Wed Oct 13, 2004 4:00 am

Obtaining Index of Rectangle Array

Post by tirby » Fri Nov 05, 2010 8:42 pm

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 !!

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Obtaining Index of Rectangle Array

Post by Narcís » Mon Nov 08, 2010 10:03 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

tirby
Newbie
Newbie
Posts: 16
Joined: Wed Oct 13, 2004 4:00 am

Re: Obtaining Index of Rectangle Array

Post by tirby » Mon Nov 08, 2010 4:49 pm

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.
Attachments
ChartTest.Zip
(8.88 KiB) Downloaded 676 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Obtaining Index of Rectangle Array

Post by Narcís » Tue Nov 09, 2010 9:39 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

tirby
Newbie
Newbie
Posts: 16
Joined: Wed Oct 13, 2004 4:00 am

Re: Obtaining Index of Rectangle Array

Post by tirby » Tue Nov 09, 2010 3:10 pm

Sorry about that,

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

Thanks
Attachments
MyProject.Zip
(6.12 KiB) Downloaded 694 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Obtaining Index of Rectangle Array

Post by Narcís » Tue Nov 09, 2010 3:38 pm

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
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

tirby
Newbie
Newbie
Posts: 16
Joined: Wed Oct 13, 2004 4:00 am

Re: Obtaining Index of Rectangle Array

Post by tirby » Tue Nov 09, 2010 10:59 pm

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Obtaining Index of Rectangle Array

Post by Narcís » Wed Nov 10, 2010 9:48 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

tirby
Newbie
Newbie
Posts: 16
Joined: Wed Oct 13, 2004 4:00 am

Re: Obtaining Index of Rectangle Array

Post by tirby » Wed Nov 10, 2010 7:00 pm

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"
Attachments
Chart1.Zip
(15.81 KiB) Downloaded 707 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Obtaining Index of Rectangle Array

Post by Narcís » Thu Nov 11, 2010 11:29 am

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
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

tirby
Newbie
Newbie
Posts: 16
Joined: Wed Oct 13, 2004 4:00 am

Re: Obtaining Index of Rectangle Array

Post by tirby » Thu Nov 11, 2010 4:55 pm

Thanks for all your help Narcis.

One last question:

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

Thanks!

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Obtaining Index of Rectangle Array

Post by Narcís » Fri Nov 12, 2010 8:17 am

Hi tirby,

Like this:

Code: Select all

    rect(rectcount).Shape.Font.Color = Color.Red
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply