Using HitTest to interact with NRectangularCallout


https://www.nevron.com/Forum/Topic12513.aspx
Print Topic | Close Window

By Kasper Juul Larsen - 6 Years Ago
Hello,
Is there a way to use HitTest to interact with callouts (NRectangularCallout)?

The idea is to create and display callouts when clicking on line series, and const lines in my chart. Then if the user clicks inside the callout I would like to close it again. 

Best regards
Kasper
By Nevron Support - 6 Years Ago
Hi Kasper,
Yes you can detect that the user clicked on a callout - the following sample shows how to use the Object property of the NHitTestResult object to achieve that:
using Nevron.Chart;
using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

NRectangularCallout m_Callout;
NChart m_Chart;

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

NLineSeries line = new NLineSeries();

for (int i = 0; i < 10; i++)
{
line.Values.Add(i);
}

m_Chart.Series.Add(line);

m_Callout = new NRectangularCallout();
m_Callout.Text = "Some Text";
m_Callout.UseAutomaticSize = true;
m_Callout.Anchor = new NDataPointAnchor(line, 1, ContentAlignment.MiddleCenter, StringAlignment.Center);
m_Chart.ChildPanels.Add(m_Callout);

nChartControl1.MouseDown += NChartControl1_MouseDown;
}

private void NChartControl1_MouseDown(object sender, MouseEventArgs e)
{
NHitTestResult result = nChartControl1.HitTest(new Point(e.X, e.Y));
if (m_Callout == result.Object)
{
m_Chart.ChildPanels.Remove(m_Callout);
m_Callout = null;
nChartControl1.Refresh();
}
}
}
}
Hope this helps - let us know if you meet any problems or have any questions.