Page 1 of 1
Mouse XY at click question
Posted: Fri Oct 19, 2012 2:05 pm
by 13052810
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
Re: Mouse XY at click question
Posted: Fri Oct 19, 2012 2:21 pm
by narcis
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!
Re: Mouse XY at click question
Posted: Fri Oct 19, 2012 3:12 pm
by 13052810
Thanks Narcis!
I think this will work!