Page 1 of 1

SnapToPoint not "snapping"

Posted: Fri Aug 31, 2007 8:01 pm
by 9232632
Hello everyone. I have the trial version of the TeeChart .Net controls (getting ready to switch from VCL) and have run into a problem. I have a chart with a series and a CursorTool that I want to use to select the nearest point in the series. If I turn the Snap property to true, it works fine with the vertical line snapping to the nearest series as I move the cursor across the chart. But when I set Snap to false and programmatically call chartTool1.SnapToPoint(), nothing happens and the return value of SnapToPoint is always -1.

Here's the function I wrote to do this.

Code: Select all

    private void tChart_MouseUp(object sender, MouseEventArgs e)
    {
      // use: handle when the user lets go of the mouse button
      // inputs:
      // returns:
      //  none
      
      // if the user is not zooming and using the left button, snap-to and select the nearest data point
      if ((!zooming)&&(e.Button == MouseButtons.Left))
      {
        cursorTool1.SnapToPoint();
        lblSelectedDate.Text = cursorTool1.XValue.ToString();
        colorLine3.Value = cursorTool1.XValue;
      }
      else
      {
        cursorTool1.Active = true;
        zooming = false;
      }
Can anyone think of what I might be doing wrong?

Thanks,
Randall

Posted: Mon Sep 03, 2007 7:54 am
by narcis
Hi Randall,

Have you set CursorTool's series? As SnapToPoint can only be used when series property is not null, otherwise the result will be always -1.

Posted: Tue Sep 04, 2007 3:05 pm
by 9232632
Hello Narcis,

Yes, I do have the CursorTool series set to one of the point series on the chart. I've tried setting it other series on the same chart with the same result. I also set the CursorTool's series property in the code just before calling the SnapToPoint method and it doesn't seem to have any effect either.

Again, setting the CursorTool's Snap property to true seems to work fine. From there if set Snap to false and call SnapToPoint(), it does nothing and returns a -1.

Any other ideas what I may be doing (or not doing)?

Thanks,
Randy

Posted: Tue Sep 04, 2007 3:23 pm
by narcis
Hi Randy,

Thanks for the information. Could you please send us a simple example project we can run "as-is" to reproduce the problem here?

You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Thanks in advance.

Posted: Tue Sep 04, 2007 4:15 pm
by 9232632
Hello again Narcis,

I created a simple application in Visual Studio 2005 that demonstrates the problem I'm having and uploaded it to your upload page. In the application, I'm displaying the current XValue of the CursorTool as it's moving, the XValue after calling SnapToPoint and the return value of the SnapToPoint method.

Thank you again,
Randy

Posted: Wed Sep 05, 2007 7:45 am
by narcis
Hi Randy,

Thanks for the example project. Sorry, my bad, now I've checked that at the SnapToPoint implementation it only works when Snap=true. In that case, you can set Snap=true call SnapToPoint and set Snap=false again. Something like this:

Code: Select all

    private void tChart1_Click(object sender, EventArgs e)
    {
      // use: show the x value and the return value when SnapToPoint is called
			cursorTool1.Snap = true;
      int returnVal = cursorTool1.SnapToPoint();
      lblReturn.Text = returnVal.ToString();
      lblAfter.Text = cursorTool1.XValue.ToString();

      // mark the cursorTool.XValue to highlight
      colorLine1.Value = cursorTool1.XValue;
			cursorTool1.Snap = false;
    }

Posted: Wed Sep 05, 2007 2:07 pm
by 9232632
Hi Narcis,

That works perfectly. Thank you so much for all of your help with this issue.

Have a great day,
Randy

Posted: Wed Sep 05, 2007 2:09 pm
by narcis
Hi Randy,

You're very welcome! I'm glad to hear that helped.

Thanks and have a nice day too.