Selecting a DrawLine that is programatically drawn

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Snarkle
Newbie
Newbie
Posts: 91
Joined: Wed Jun 30, 2010 12:00 am

Selecting a DrawLine that is programatically drawn

Post by Snarkle » Thu Jul 15, 2010 7:24 am

Greetings,

I have problem that I'm not sure how to word properly .. but here goes.

I have several Drawlines that I have programatically drawn on the Chart (pulling the coords from a DB)
I do the same with a number of Series also drawn on the chart programatically.

Now when I want to modify a series I click on it and the TChart_ClickSeries(...) event tells me what the series is and I can go off and do whatever.
Is there a similiar event that I can use to detect when the user has clicked on a DrawLine ?

below is the code I use to draw EACH trendline individually ... rather than having several lines in 1 drawline ... I draw a line then add it to the Tools collection.

Code: Select all

private void drawTrendLine(ref TChart StockChart, double x0, double y0, double x1, double y1)
         {
             DrawLine drawLine1 = new DrawLine();
             DrawLineItem dItem = new DrawLineItem(drawLine1);
             dItem.StartPos = new PointDouble(x0, y0);
             dItem.EndPos = new PointDouble(x1, y1);
             dItem.Pen.Color = Color.Blue;
             dItem.Pen.Width = 2;
             dItem.Pen.Transparency = 50;
             drawLine1.EnableDraw = false;
             drawLine1.EnableSelect = true;
             StockChart.Tools.Add(drawLine1);
         }
This works fine and gives me control over each line .. but the problem I have is what to do when a user loads up their saved trend lines and moves it ... I dont know how to 1) Identify which line has been selected and thus how to update the coords of the line in my DB.

If I could identify a particualr DrawLine I could register the DraggedLine event handler for it and get my coords that way .. unless there is a better way ?
Ive been trying to use the Selector Tool but it seems to find everything except Drawlines.

Cheers Phil.

Snarkle
Newbie
Newbie
Posts: 91
Joined: Wed Jun 30, 2010 12:00 am

Re: Selecting a DrawLine that is programatically drawn

Post by Snarkle » Fri Jul 16, 2010 5:16 am

I have a kind of workaround ... I would like to know whether there is a better way but until then ... this is how I select a Drawline.

Step 1. Programatically draw all the DrawLines using values in a DB. (see above code) note. this is done in a class outside my Chart Class.
Step 2. Within the Chart class , reattach DrawLine Events.

Code: Select all

            foreach (Tool theTool in StockChart.Tools)
            {
                if (theTool.GetType() == typeof(DrawLine))
                {
                    ((DrawLine)theTool).EnableSelect = true;
                    ((DrawLine)theTool).DraggedLine += new DrawLineEventHandler(drawLine_DraggedLine);
                    ((DrawLine)theTool).Select += new DrawLineEventHandler(ControlChart_Select);
                }
            }
Step 3. WIthin the events handler(s) Find the index

Code: Select all

void ControlChart_Select(DrawLine sender)
        {
                        Debug.Print("Index:" + (StockChart.Tools.IndexOf( sender)).ToString());
        }
This works but I am wondering if there is a simpler way .. or another way that does not use index's .. such as names or title ????

Cheers Phil.
--------------------
Cheers Phil.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Selecting a DrawLine that is programatically drawn

Post by Sandra » Fri Jul 16, 2010 9:08 am

Hello Phil,

I suggest a simpler code, for selecting index of lines that you are drawing with DrawLine Tool and you can use it in your application. Unlike with your code is that this use DrawLine.Lines.IndexOf() to calculate index of line that you have selected.

Code: Select all

 private Steema.TeeChart.Styles.Line line1;
        private Steema.TeeChart.Tools.DrawLine drawline1;
        private void InitializeChart()
        {
            line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            line1.FillSampleValues();

            drawline1 = new Steema.TeeChart.Tools.DrawLine(tChart1.Chart);
            drawline1.Pen.Color = Color.Blue;
            drawline1.Select += new Steema.TeeChart.Tools.DrawLineEventHandler(drawline1_Select);

        }
        void drawline1_Select(Steema.TeeChart.Tools.DrawLine sender)
        {
            Steema.TeeChart.Tools.DrawLineItem I = drawline1.Selected;
            this.Text = drawline1.Lines.IndexOf(I).ToString();
        }
Could you please, tell us if previous code works as you want?


I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / 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