VintaSoft Annotation .NET Plug-in Discussions

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

Board index < VintaSoft Imaging < VintaSoft Annotation .NET Plug-in Discussions

We are migrating to new forums engine, no new registration or posting currently available. TIA for your patience.

How to subscribe 'DeleteKeyPressed' event properly?



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!


Re: How to subscribe 'DeleteKeyPressed' event properly?

Post by Yuri »

Please use the code below:
        // 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


Re: How to subscribe 'DeleteKeyPressed' event properly?

Post by leopsc »

Thanks! It works.


Page 1 from 1: 1