TeeChart:扩展 Line/FastLine 的 "clickable" 宽度

TeeChart: Expand the "clickable" width of a Line/FastLine

我有一个 WinForms 应用程序,其中在 TeeChart 组件中绘制了多条线。要求可以通过右键单击一行来删除它。

一切正常,clickseries事件被捕获等等,但是用户发现右键单击很难命中线。问题是,是否可以增加 Line/FastLine 对象对点击敏感的区域?即,在不在屏幕上将线画得更宽的情况下,使线变宽。

提前发送

是的,这是可能的。实现这一目标的关键是 PointInLineTolerance method. To achieve what you request you can combine it with NearestPoint's tool GetNearestPoint method,如本例所示:

public Form1()
{
  InitializeComponent();
  InitializeChart();
}

private void InitializeChart()
{
  tChart1.Aspect.View3D = false;

  tChart1.Series.Add(new Steema.TeeChart.Styles.Line()).FillSampleValues();
  tChart1.MouseMove += TChart1_MouseMove;
}

private void TChart1_MouseMove(object sender, MouseEventArgs e)
{
  var nearestPoint = new Steema.TeeChart.Tools.NearestPoint(tChart1[0]);
  nearestPoint.Active = false;
  var p = new Point(e.X, e.Y);
  var index = nearestPoint.GetNearestPoint(p);

  if (index != -1)
  {
    const int tolerance = 10;
    var px = tChart1[0].CalcXPos(index);
    var py = tChart1[0].CalcYPos(index);

    var index2 = (index == tChart1[0].Count - 1) ? index - 1 : index + 1;
    var qx = tChart1[0].CalcXPos(index2);
    var qy = tChart1[0].CalcYPos(index2);

    if (Steema.TeeChart.Drawing.Graphics3D.PointInLineTolerance(p, px, py, qx, qy, tolerance))
    {
      tChart1.Header.Text = "point " + index.ToString() + " clicked";
    }
    else
    {
      tChart1.Header.Text = "No point";
    } 
  }

另一种方法是使用与原始系列具有相同数据的隐形假系列。