How to subscribe 'DeleteKeyPressed' event properly?

Questions, comments and suggestions concerning VintaSoft Annotation .NET Plug-in.

Moderator: Alex

Post Reply
leopsc
Posts: 4
Joined: Thu Mar 24, 2011 2:36 pm

How to subscribe 'DeleteKeyPressed' event properly?

Post 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?

thanks!
Yuri
Posts: 64
Joined: Wed Jul 23, 2008 2:47 pm

Re: How to subscribe 'DeleteKeyPressed' event properly?

Post 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);
            collection.Remove(annot);
            annot.Dispose();
            // select next annotation
            if (collection.Count != 0)
            {
                if (index == collection.Count)
                    index--;
                collection.SelectedAnnotation = collection[index];
            }
        }

        private void annotationViewer1_DeleteKeyPressed(object sender, EventArgs e)
        {
            // insert your code here
            
            // remove selected annotation
            if (annotationViewer1.FocusedImage == null)
                return;
            if (annotationViewer1.Focused && annotationViewer1.Annotations.SelectedCollection.SelectedAnnotation != null)
            {
                RemoveSelectedAnnotation();
                return;
            }
        }
Sincerely
leopsc
Posts: 4
Joined: Thu Mar 24, 2011 2:36 pm

Re: How to subscribe 'DeleteKeyPressed' event properly?

Post by leopsc »

Thanks! It works.
Post Reply