peterz Posted February 27, 2008 Report Share Posted February 27, 2008 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? Quote Link to comment Share on other sites More sharing options...
Frank Posted February 28, 2008 Report Share Posted February 28, 2008 Only a small change needs to be made: Replace: HitTestEventArgs ht = chart1.HitTest(point.X, point.Y); with: 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. Quote Link to comment Share on other sites More sharing options...
peterz Posted February 29, 2008 Author Report Share Posted February 29, 2008 Thanks Frank, that worked. I thought I had tried setting the flag to true but that must have been with differnet code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.