
Highlight a line when the cursor is on the line
Posted Friday, 10 June, 2011 - 21:56 by adityatan inHello:
How do I highlight a line when the cursor is on it? The attached picture might help you to visualize the problem.
I have started but can't really solve the problem. As a start, below is the current code (it doesn't work) for the MouseEventArgs:
private void glControl1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if (!loaded) return; for (int ii = 0; ii < UIElementsEnd.Count; ii++) { if (e.Location.X / xmag == UIElementsStart.ElementAt(ii).X && e.Location.X / xmag == UIElementsEnd.ElementAt(ii).X) { if (UIElementsStart.ElementAt(ii).Y < (e.Location.Y / ymag) && (e.Location.Y / ymag) < UIElementsStart.ElementAt(ii).Y) { UIElementsHighlightStart.Add(UIElementsStart.ElementAt(ii)); UIElementsHighlightEnd.Add(UIElementsEnd.ElementAt(ii)); } } if (e.Location.Y / ymag == UIElementsStart.ElementAt(ii).Y && e.Location.Y / ymag == UIElementsEnd.ElementAt(ii).Y) { if (UIElementsStart.ElementAt(ii).X < (e.Location.X / xmag) && (e.Location.X / xmag) < UIElementsStart.ElementAt(ii).X) { UIElementsHighlightStart.Add(UIElementsStart.ElementAt(ii)); UIElementsHighlightEnd.Add(UIElementsEnd.ElementAt(ii)); } } } UIElementsHighlightStart.Clear(); UIElementsHighlightEnd.Clear(); }
Below is the code for the PaintEventArgs:
private void glControl1_Paint(object sender, PaintEventArgs e) { GL.LineWidth(4f); GL.Color3(Color.Green); GL.Begin(BeginMode.Lines); if (UIElementsHighlightStart.Count != 0) { GL.Vertex2(UIElementsHighlightStart.ElementAt(0).X * xmag, UIElementsHighlightStart.ElementAt(0).Y * ymag); GL.Vertex2(UIElementsHighlightEnd.ElementAt(0).X * xmag, UIElementsHighlightEnd.ElementAt(0).Y * ymag); } GL.End(); glControl1.Invalidate(); }
Thanks much guys.
AT


Comments
Re: Highlight a line when the cursor is on the line
I found the solution!
Thanks for checking it out guys!
AT