Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
425
Annotation click event
posted

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.

Parents
No Data
Reply
  • 53790
    Verified Answer
    posted

    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

     

    Video040.rar
Children