This is a migrated thread and some comments may be shown as answers.

Get Next/Previous Annotation Types (code sample)

0 Answers 64 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 18 May 2012, 12:25 PM
Here is a code sample that gets the Type Of the Next & Previous Annotation at the caret position.
.
Get TypeOf Next Annotation:
public static AnnotationRangeMarkerBase GetNextAnnotationMarker(this RadDocument document)
{
    if (!document.Selection.IsEmpty)
    {
        document.CaretPosition.MoveToPosition(document.Selection.Ranges.Last.EndPosition);
    }
 
    InlineLayoutBox inlineLayoutBox = document.CaretPosition.GetCurrentInlineBox();
    while (inlineLayoutBox != null && !(inlineLayoutBox.AssociatedInline is AnnotationRangeMarkerBase))
    {
        inlineLayoutBox = (InlineLayoutBox)DocumentStructureCollection.GetNextElementOfType(inlineLayoutBox, typeof(AnnotationMarkerLayoutBox));
    }
 
    if (inlineLayoutBox == null)
    {
        return null;
    }
 
 
    AnnotationRangeMarkerBase annotationMarker = inlineLayoutBox.AssociatedInline as AnnotationRangeMarkerBase;
    if (annotationMarker == null)
    {
        return null;
    }
 
    return annotationMarker;
}


Get TypeOf Previous Annotation:
public static AnnotationRangeMarkerBase GetPreviousAnnotationMarker(this RadDocument document)
{
    if (!document.Selection.IsEmpty)
    {
        document.CaretPosition.MoveToPosition(document.Selection.Ranges.Last.StartPosition);
    }
 
    InlineLayoutBox inlineLayoutBox = document.CaretPosition.GetCurrentInlineBox();
    do
    {
        inlineLayoutBox = (InlineLayoutBox)DocumentStructureCollection.GetPreviousElementOfType(inlineLayoutBox, typeof(AnnotationMarkerLayoutBox));
    }
    while (inlineLayoutBox != null && !(inlineLayoutBox.AssociatedInline is AnnotationRangeStart));
 
    if (inlineLayoutBox == null)
    {
        return null;
    }
 
    return inlineLayoutBox.AssociatedInline as AnnotationRangeMarkerBase;
}


This is how you can use the methods:
//Get the previous annotation type
AnnotationRangeMarkerBase previousAnnotationType = RadDocumentExtensions.GetPreviousAnnotationMarker(radRichTextBox.Document);
 
 
//Get the next annotation type
AnnotationRangeMarkerBase nextAnnotationType = RadDocumentExtensions.GetNextAnnotationMarker(radRichTextBox.Document);

I hope this help you as it did me.

p.s. This code was mostly given to me by the Telerik support team via a ticket that I sent.

No answers yet. Maybe you can help?

Tags
RichTextBox
Asked by
Robert
Top achievements
Rank 1
Share this question
or