Creating a Parallel Line

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Quant
Advanced
Posts: 142
Joined: Tue Dec 30, 2014 12:00 am

Creating a Parallel Line

Post by Quant » Fri Jun 12, 2015 7:16 am

Dear Steema,

Currently we are having a requirement wherein we need to do following:
1] Select Already Drawn TrendLine (DrawLine Tool)
2] On right click that line, it should show a Context Menu having menu items like "Line Properties", "Create Parallel Line"
3] On click of "Create Parallel Line" it should create identical line which should be placed at some distance and parallel to original line.

For your reference check following screenshot:
Parallel Line.png
Parallel Line.png (8.41 KiB) Viewed 2764 times
Any help on this would be greately appreciated.

Note: Prior to give help on above topic, please let us know a better approch to show context menu on right click of DrawLine tool ASAP.

Christopher
Guru
Posts: 1229
Joined: Fri Nov 15, 2002 12:00 am

Re: Creating a Parallel Line

Post by Christopher » Fri Jun 12, 2015 8:50 am

You can try:

Code: Select all

    DrawLine tool;
    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      tChart1.Series.Add(typeof(Points)).FillSampleValues(200);
      tChart1.MouseClick += tChart1_MouseClick;

      tool = new DrawLine(tChart1.Chart);

      DrawLineItem l = new DrawLineItem(tool);

      l.StartPos = new PointDouble(tChart1[0].XValues[50], tChart1[0].YValues[50]);
      l.EndPos = new PointDouble(tChart1[0].XValues[100], tChart1[0].YValues[100]);

      tool.Selected = l;
    }


    DrawLineItem item;
    void tChart1_MouseClick(object sender, MouseEventArgs e)
    {
      if(e.Button == System.Windows.Forms.MouseButtons.Right)
      {
        item = tool.Clicked(e.X, e.Y);
        if (item != null)
        {
          ContextMenu m = new ContextMenu();
          m.MenuItems.Add(new MenuItem("Line Properties"));
          m.MenuItems.Add(new MenuItem("Create Parallel Line"));

          m.MenuItems[1].Click += SurfaceTest_Form_Click;

          m.Show(tChart1, new Point(e.X, e.Y));
        }
      }
    }

    void SurfaceTest_Form_Click(object sender, EventArgs e)
    {
      DrawLineItem l = new DrawLineItem(tool);

      l.StartPos = new PointDouble(item.StartPos.X, item.StartPos.Y + 100);
      l.EndPos = new PointDouble(item.EndPos.X, item.EndPos.Y + 100);

      tool.Invalidate();
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Quant
Advanced
Posts: 142
Joined: Tue Dec 30, 2014 12:00 am

Re: Creating a Parallel Line

Post by Quant » Fri Jun 12, 2015 9:08 am

Thanks a lot for your prompt reply.

Quant
Advanced
Posts: 142
Joined: Tue Dec 30, 2014 12:00 am

Re: Creating a Parallel Line

Post by Quant » Wed Sep 09, 2015 7:35 am

we are facing following problems with this work around
1) we cant sync the movement of both lines
2) change of angle in one line cant sync with other

we require some thing similar to HorizParallel and VertParallel but with slope angle change functionality with mouse.

Christopher
Guru
Posts: 1229
Joined: Fri Nov 15, 2002 12:00 am

Re: Creating a Parallel Line

Post by Christopher » Wed Sep 09, 2015 1:30 pm

Quant wrote:we are facing following problems with this work around
1) we cant sync the movement of both lines
2) change of angle in one line cant sync with other

we require some thing similar to HorizParallel and VertParallel but with slope angle change functionality with mouse.
Maybe something like this:

Code: Select all

    DrawLine tool;
    DrawLineItem item;
    List<Tuple<DrawLineItem, DrawLineItem>> pairs = new List<Tuple<DrawLineItem, DrawLineItem>>();

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      tChart1.Series.Add(typeof(Points)).FillSampleValues(200);
      tChart1.MouseDown += TChart1_MouseDown;
      tChart1.MouseMove += TChart1_MouseMove;

      tool = new DrawLine(tChart1.Chart);

      DrawLineItem l = new DrawLineItem(tool);

      l.StartPos = new PointDouble(tChart1[0].XValues[50], tChart1[0].YValues[50]);
      l.EndPos = new PointDouble(tChart1[0].XValues[100], tChart1[0].YValues[100]);

      tool.Selected = l;
    }

    private void TChart1_MouseDown(object sender, MouseEventArgs e)
    {
      item = tool.Clicked(e.X, e.Y);

      if (e.Button == System.Windows.Forms.MouseButtons.Right)
      {
        if (item != null)
        {
          ContextMenu m = new ContextMenu();
          m.MenuItems.Add(new MenuItem("Line Properties"));
          m.MenuItems.Add(new MenuItem("Create Parallel Line"));

          m.MenuItems[1].Click += SurfaceTest_Form_Click;

          m.Show(tChart1, new Point(e.X, e.Y));
        }
      }
    }

    private void TChart1_MouseMove(object sender, MouseEventArgs e)
    {
      if(pairs.Count > 0 && item != null && item.Tag != null)
      {
        Tuple<int, int> tag = (Tuple<int, int>)item.Tag;
        Tuple<DrawLineItem, DrawLineItem> pair = pairs[tag.Item1];

        DrawLineItem partner = tag.Item2 == 0 ? pair.Item2 : pair.Item1;

        if(tag.Item2 == 0)
        {
          partner.StartPos = new PointDouble(item.StartPos.X, item.StartPos.Y + 100);
          partner.EndPos = new PointDouble(item.EndPos.X, item.EndPos.Y + 100);
        }
        else
        {
          partner.StartPos = new PointDouble(item.StartPos.X, item.StartPos.Y - 100);
          partner.EndPos = new PointDouble(item.EndPos.X, item.EndPos.Y - 100);
        }

        tool.Invalidate();
      }
    }

    void SurfaceTest_Form_Click(object sender, EventArgs e)
    {
      DrawLineItem l = new DrawLineItem(tool);

      l.StartPos = new PointDouble(item.StartPos.X, item.StartPos.Y + 100);
      l.EndPos = new PointDouble(item.EndPos.X, item.EndPos.Y + 100);

      pairs.Add(new Tuple<DrawLineItem, DrawLineItem>(item, l));
      item.Tag = new Tuple<int, int>(pairs.Count - 1, 0);
      l.Tag = new Tuple<int, int>(pairs.Count - 1, 1);

      tool.Invalidate();
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply