Using HitTest to interact with NRectangularCallout


Author
Message
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K
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.

Best Regards,
Nevron Support Team


Kasper Juul Larsen
Kasper Juul Larsen
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
Posts: 3, Visits: 5
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
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search