Page 1 of 1

Changing arrow colors on mouse hover

Posted: Tue Jun 12, 2018 8:17 am
by 15680965
Is it possible to change the arrows color on mouse hover over the arrows? Thanks for any help.

Re: Changing arrow colors on mouse hover

Posted: Wed Jun 13, 2018 8:22 am
by Christopher
Hello,

this is possible, but unfortunately it seems there is a bug in the Arrow Series by which the Clicked() method is not returning the correct series point index - I have added this issue to our bug-tracking software with id=2041. However, there is a simple workaround which involves deriving a new class from the Arrow series and overriding the Clicked() method, which can be seen here:

Code: Select all

	public partial class Form1 : Form
	{
		private MyArrow series;
		public Form1()
		{
			InitializeComponent();

			series = new MyArrow(tChart1.Chart);
			series.FillSampleValues();
			tChart1.MouseMove += TChart1_MouseMove;
		}

		int oldIndex = -1;
		private void TChart1_MouseMove(object sender, MouseEventArgs e)
		{
			int index = series.Clicked(e.X, e.Y);
			Color oldColor = Utils.EmptyColor;
			if (index > -1)
			{
				oldColor = series[index].Color;
				series[index].Color = Color.Red;
				if (oldIndex > -1)
				{
					series[oldIndex].Color = oldColor;
				}
				oldIndex = index;
			}

			tChart1.Invalidate();
		}
	}

	public class MyArrow : Arrow
	{
		public MyArrow(Chart c) : base(c) {}

		public override int Clicked(int x, int y)
		{
			Graphics3D g = Chart.Graphics3D;
			for (int i = 0; i < Count; i++)
			{
				Point p0 = new Point(CalcXPos(i), CalcYPos(i));
				Point p1 = new Point(CalcXPosValue(EndXValues[i]), CalcYPosValue(EndYValues[i]));

				Point[] points = g.GetArrowPoints(p0, p1, Pointer.HorizSize, Pointer.VertSize, MiddleZ, 50.0);

				if (points!= null && Graphics3D.PointInPolygon(new Point(x, y), points)) return i;
			}

			return -1;
		}
	}