Mouse XY at click question

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
tirby
Newbie
Newbie
Posts: 84
Joined: Mon Mar 16, 2009 12:00 am

Mouse XY at click question

Post by tirby » Fri Oct 19, 2012 2:05 pm

Hi!

I'm trying to get the X and Y coordinates of a mouse click in such a way that the coordinates are based on the X and Y values of an axis. I would think that in part, the axis used would have to be specified as in the case of the Y axis where there could be several axes.

Can someone guide me how to do this in VB.Net or C#?

Thanks

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Mouse XY at click question

Post by Narcís » Fri Oct 19, 2012 2:21 pm

Hi tirby,

Yes, you can do something like this:

Code: Select all

    public Form1()
    {
      InitializeComponent();
      InitializeChart();
    }

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;

      tChart1.Series.Add(new Steema.TeeChart.Styles.Line()).FillSampleValues();
      tChart1.Series.Add(new Steema.TeeChart.Styles.Line()).FillSampleValues();

      tChart1.Axes.Left.EndPosition = 50;

      Steema.TeeChart.Axis axis1 = new Steema.TeeChart.Axis();
      axis1.StartPosition = 50;
      tChart1.Axes.Custom.Add(axis1);
      tChart1[1].CustomVertAxis = axis1;

      tChart1.MouseClick += new MouseEventHandler(tChart1_MouseClick);
    }

    void tChart1_MouseClick(object sender, MouseEventArgs e)
    {
      Steema.TeeChart.Axis axis = new Steema.TeeChart.Axis();

      for (int i = 0; i < tChart1.Axes.Count; i++)
      {
        axis = tChart1.Axes[i];

        if (!axis.Horizontal)
        {
          if (axis.Clicked(axis.Position,e.Y))
	        {
            break;
	        }
        }
      }

      double x = tChart1.Axes.Bottom.CalcPosPoint(e.X);
      double y = axis.CalcPosPoint(e.Y);

      tChart1.Header.Text = x.ToString("#.##") + " - " + y.ToString("#.##");
    }
Hope this helps!
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

tirby
Newbie
Newbie
Posts: 84
Joined: Mon Mar 16, 2009 12:00 am

Re: Mouse XY at click question

Post by tirby » Fri Oct 19, 2012 3:12 pm

Thanks Narcis!

I think this will work!

Post Reply