Page 1 of 1

How to subscribe 'DeleteKeyPressed' event properly?

Posted: Mon Mar 28, 2011 4:08 pm
by leopsc
I have an AnnotationViewer control and I subscribed the 'DeleteKeyPressed' event.

The problem is that, when I select a LineAnnotation (that is inside of the annotationViewer) and delete it, the event occurs but the the selected annotation (linneAnnotation) doesn't delete after my subscribed method event occurs.

I've already tryed to call base method DeleteKeyPressed but it doesn't exists and an error is given.

When I remove the DeleteKeyPressed event, all works out.

What should I do to subscribe the event and delete the SelectedAnnotation too?


Re: How to subscribe 'DeleteKeyPressed' event properly?

Posted: Wed Mar 30, 2011 9:45 am
by Yuri
Please use the code below:

Code: Select all

        // Remove selected annotation.
        private void RemoveSelectedAnnotation()
            AnnotationCollection collection = annotationViewer1.Annotations.SelectedCollection;
            AnnotationBase annot = collection.SelectedAnnotation;
            // remove annotation
            collection.SelectedAnnotation = null;
            int index = collection.IndexOf(annot);
            // select next annotation
            if (collection.Count != 0)
                if (index == collection.Count)
                collection.SelectedAnnotation = collection[index];

        private void annotationViewer1_DeleteKeyPressed(object sender, EventArgs e)
            // insert your code here
            // remove selected annotation
            if (annotationViewer1.FocusedImage == null)
            if (annotationViewer1.Focused && annotationViewer1.Annotations.SelectedCollection.SelectedAnnotation != null)

Re: How to subscribe 'DeleteKeyPressed' event properly?

Posted: Wed Mar 30, 2011 4:59 pm
by leopsc
Thanks! It works.