Jump to content
Software FX Community

HitTest accuracy


Recommended Posts

I'm trying to use the HitTest method to detemine the chart object the mouse is over while dragging something onto a chart. The results are not what I expected. Here is my scenario using the ChartFx MouseEvents sample:

1. Set AllowDrop = true in Form1_Load

2. Add this code to Form1:

protected override void OnDragOver(DragEventArgs e)


Point point = chart1.PointToClient(new Point(e.X, e.Y));

HitTestEventArgs ht = chart1.HitTest(point.X, point.Y);

System.Diagnostics.Debug.WriteLine(string.Format("HitType={0} ({1}, {2})", ht.HitType, ht.AbsoluteLocation, point));

e.Effect = DragDropEffects.Copy;


3. Run the sample.

4. Move the mouse (no drag yet) to the bottom left corner of the axes intersection (ie. 0, 0 -- the origin).

5. Note the Mouse Position value, I see 67,264 and the Chart Element is Axis: Main X Axis

6. Now drag some data (ie. text from any drag enabled source) to the same point -- don't drop it, just move the drag cursor so it points to the origin.

7. Note the debug output in the IDE, I see x=74, y=271

The location of point and ht.AbsoluteLocation are always off by 7 pixels. What am I doing wrong with the call tto HitTest?

Link to comment
Share on other sites

Only a small change needs to be made:


HitTestEventArgs ht = chart1.HitTest(point.X, point.Y);


HitTestEventArgs ht = chart1.HitTest(point.X, point.Y,true);

The true at the end is for Absolute position, otherwise the position is assumed to be inside the chart's "Drawing Area" which excludes the border, toolbar, legend box and DataGrid.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...