Is there a way to recognize when an Annotation has been clicked through the ultrachart? What I'm wanting is to know which annotation was clicked, and display a context menu when it is right clicked. If it helps at all I'm useing BoxAnnotations and a composite chart.
Hello Bryan,
Maybe one possible approach to solve this task could be if you are using BoxAnnotation with LocationType in Pixels. By this way we could handle MouseClick event and compare your current MouseClick location with the locations of our BoxAnnotations. To create BoxAnnotation I`m using the code:
BoxAnnotation ba = new BoxAnnotation();
ba.Text ="Test 1";
ba.Location.Type =LocationType.Pixels;
ba.FillColor =Color.Yellow;
ba.Visible =true;
ba.Border.CornerRadius = 10;
ba.Width = 50;
ba.Location.LocationX = 340;
ba.Location.LocationY = 140;
ultraChart1.Annotations.Annotations. Add(ba);
Also here is the MouseClick event. Of course you could extend the IF condition to be more accurate:
private void ultraChart1_MouseClick(object sender, MouseEventArgs e)
{
foreach (Annotation ann in ultraChart1.Annotations.Annotations)
if (ann.GetType() == typeof(BoxAnnotation) && ((BoxAnnotation)ann).Location.LocationX <= e.Location.X && ((BoxAnnotation)ann).Location.LocationX + ((BoxAnnotation)ann).Width >= e.Location.X)
MessageBox.Show("Annotation: " + ((BoxAnnotation)ann).Text);
Debug.WriteLine("Annotation: " + ((BoxAnnotation)ann).Text);
}
Please take a look at the attached video file for more details and let me know if you have any questions.
Regards
Have you been able to resolve your issue ? Did you try my suggestion ?If you still have any concerns or questions I will be glad to help. If you need any additional assistance don’t hesitate to ask.
This was a workable solution to my issue especially since I had already been positioning the annotations by pixels.
Thanks for the feedback !