Profile Picture

How to drag a line?

Posted By Enjoyear Guo 13 Years Ago
Author
Message
Nevron Support
Posted 4 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: 3 hours ago
Posts: 3,054, Visits: 4,009
Hi Casper,
You can take a look at the WinForms \ All Examples \ Interactivity \ Tools \ Custom Drag Tool example - it shows how to implement a custom dragging tool - the example uses const lines as dragging targets. Let us know if you meet any problems or have any questions.

Best Regards,
Nevron Support Team



Kasper Juul Larsen
Posted 4 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: 4 Years Ago
Posts: 3, Visits: 5
I am trying to do the same, only with a horizontal constant line. How can I do this?

Enjoyear Guo
Posted 13 Years Ago
View Quick Profile
Forum Member

Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 30, Visits: 1
It works great!! Thanks!

Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: 3 hours ago
Posts: 3,054, Visits: 4,009

Hi Enjoyear,

Yes you can easily achieve const line drag behaviour by intercepting the mouse down, move and up events - for example:

  private void Form1_Load(object sender, EventArgs e)
  {
   NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];

   NBarSeries bar = new NBarSeries();
   bar.Values.Add(10);
   bar.Values.Add(20);
   bar.Values.Add(30);

   chart.Series.Add(bar);

   NAxisConstLine constLine = new NAxisConstLine();
   constLine.Value = 1;
   chart.Axis(StandardAxis.PrimaryX).ConstLines.Add(constLine);

   nChartControl1.MouseDown += new MouseEventHandler(nChartControl1_MouseDown);
   nChartControl1.MouseMove += new MouseEventHandler(nChartControl1_MouseMove);
   nChartControl1.MouseUp += new MouseEventHandler(nChartControl1_MouseUp);
  }

  NAxisConstLine m_DragLine;

  void nChartControl1_MouseUp(object sender, MouseEventArgs e)
  {
   if (m_DragLine != null)
   {
    m_DragLine = null;
    nChartControl1.Capture = false;
    nChartControl1.Cursor = Cursors.Default;
   }
  }

  void nChartControl1_MouseMove(object sender, MouseEventArgs e)
  {
   if (m_DragLine != null)
   {
    NViewToScale1DTransformation viewToScale = new NViewToScale1DTransformation(nChartControl1.View.Context, nChartControl1.Charts[0], (int)StandardAxis.PrimaryX, (int)StandardAxis.PrimaryY);

    double value = 0;
    if (viewToScale.Transform(new NPointF(e.X, e.Y), ref value))
    {
     m_DragLine.Value = value;
     nChartControl1.Refresh();
    }
   }
   
  }

  void nChartControl1_MouseDown(object sender, MouseEventArgs e)
  {
   NHitTestResult result = nChartControl1.HitTest(new Point(e.X, e.Y));
   if (result.ChartElement == ChartElement.AxisConstLine)
   {
    m_DragLine = nChartControl1.Charts[0].Axis(StandardAxis.PrimaryX).ConstLines[0];
    nChartControl1.Capture = true;
    nChartControl1.Cursor = Cursors.SizeWE;
   }
  }

The idea is to check on mouse down whether the currently hit object is the const line you added and then to move it around by transforming the mouse coordinate to scale coordinates.

Hope this helps - let us know if you meet any problems...



Best Regards,
Nevron Support Team



Enjoyear Guo
questionmark Posted 13 Years Ago
View Quick Profile
Forum Member

Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 30, Visits: 1

In the nevron examples, I find the NDataPointDragTool to drag a data point, but I want to enable the user to drag some lines. For example, the user could click on the chart, which will generate a vertical line. And then I hope the user could drag this vertical line left and right to make some selection. How can I do it??

To make it clear, the way I add a vertical line is through _chart.Axis(StandardAxis.PrimaryX).ConstLines[0] . Is it possible to drag the const line?

Many thanks!

 





Similar Topics


Reading This Topic