Page 1 of 1

getting x and y coordinates of mouse

Posted: Mon Dec 15, 2008 3:55 pm
by 14045263
I've already done a search but couldn't find what I wanted...

I have a cursor tool which I have as 'invisible' (its colour is transparent), so that it can send the X and Y via an Event so that you are constantly updated with the X and Y of the chart (not control).

However I wanted to replace this with a FastCursor (so setting the property to true), but that doesn't like my transparent colour, and so draws the line as black.

Is there any other way of retrieving the X and Y of the mouse in the chart without using a Cursor Tool - I like having the CursorTool because you can retrieve both chart and control X and Y but it slows the chart down a bit with redrawing.

Thanks for any help.

Regards

Chris

Posted: Mon Dec 15, 2008 3:58 pm
by narcis
Hi Chris,

Yes, you can use TChart's MouseMove event and its e.X and e.Y arguments for getting mouse coordinates.

Hope this helps!

Posted: Mon Dec 15, 2008 4:08 pm
by 14045263
Thanks for the quick reply there Narcís.

I think I've got you, but I was wondering if there was another way to get the X and Y of the chart axis and not the chart (sorry I didn't put that in the first post), like the lowercase 'x' property of CursorChangeEventArgs, but just without using a CursorTool.

Thanks again,
Chris.

Posted: Mon Dec 15, 2008 4:31 pm
by narcis
Hi Chris,

Sorry, I should have understood that :wink:

In that case you can easily obtain axis values like this:

Code: Select all

		void tChart1_MouseMove(object sender, MouseEventArgs e)
		{
			double xVal = tChart1.Axes.Bottom.CalcPosPoint(e.X);
			double yVal = tChart1.Axes.Left.CalcPosPoint(e.Y);
		}

Posted: Tue Dec 16, 2008 9:15 am
by 14045263
Of course; that's what I wanted, cheers!

And is there definitely no way you know of to make a CursorTool (with FastCursor) have a Transparent colour, at all?!

Regards

Chris

Posted: Tue Dec 16, 2008 9:25 am
by narcis
Hi Chris,

No, this is because when FastCursor=true it uses DrawReversibleLine method for painting as I explained on this thread.

Posted: Tue Dec 16, 2008 10:13 am
by 14045263
No worries Narcís, I just wondered, that's all!

The reason I asked is that I constantly need to calculate the nearest point when you right click or are moving colourbands - I used a combination of the Interpolating Line series method and a slightly modified version of the code I found in this thread, but as I found the nearestpoint tool in the cursor itself I just use that now.
That same cursor tool sends its X and Y (of the axis) back to the form it's in via event, so i've got it doing a few things at once, which is great!
I just noticed that because of it re-drawing it was taking slightly longer to report back the X and Y of the axis, so I was just searching for some minor alternatives - I can't remove the "invisible" cursor though because it's handy in what I need!

Thanks for the help again.

Chris