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

InsertCustomAnnotationRange

5 Answers 105 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Anand
Top achievements
Rank 1
Anand asked on 06 Aug 2014, 10:21 AM
How  can I add an custom annotation in the Header and footer ? Is there a way to do it ?

Document.CaretPosition doesnt get the Header position. I dont find any move functions to move in to the Header as well ?.

I added custom annotation on the document as below :

Document.InsertCustomAnnotationRange(position, position, new RangeStart(id),  new RangeEnd());

Didn't find any functions to add custom annotations in the Header or move in to the Header  ? Could you help me in this please ?

Thanks
Anand

5 Answers, 1 is accepted

Sort by
0
Anand
Top achievements
Rank 1
answered on 07 Aug 2014, 09:39 AM
Hi All, 
I worked out my way to get the Headers and footers as below.Document.section[0].Headers.Default.Body

But weirdly, in Header, I found always the cursor position points to the starting first word of the Header. It doesnt seems to get updated even when I move the cursor around. 
I get the cursor by Document.section[0].Headers.First.Body.CaretPosition

Not sure am I missing something ?


0
Mihail
Telerik team
answered on 08 Aug 2014, 02:12 PM
Hello Anand,

 When you work with headers, footers or comments you need to use the ActiveDocumentEditor of RadRichTextBox in order to manipulate the correct part of the document.
Here is how you can get the correct caret position:
DocumentPosition carretPosition = this.radRichTextBox.ActiveDocumentEditor.Document.CaretPosition;

I would also suggest you to use the InsertAnnotationRange of ActiveDocumentEditor, which will insert the start and end annotations in the start and end position of the selection of ActiveDocumentEditor.Document. Here is example on how to do it:
this.radRichTextBox.FocusHeader();
 
this.radRichTextBox.ActiveDocumentEditor.Document.Selection.AddSelectionStart(startPosition);
this.radRichTextBox.ActiveDocumentEditor.Document.Selection.AddSelectionEnd(endPosition);
this.radRichTextBox.ActiveDocumentEditor.InsertAnnotationRange(annotationStart, annotationEnd);
 
this.radRichTextBox.ActiveDocumentEditor.Document.Selection.Clear();


I hope this information answer your question. In case you have additional questions feel free to contact us again.

Regards,
Mihail
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Anand
Top achievements
Rank 1
answered on 13 Aug 2014, 01:20 PM
Hi Mihail,
Thanks for the reply. Yes , this way I could get the current cursor position in the document ,across the Headers and Footers.
But I couldn't work out a way whether the active document (this.radRichTextBox.ActiveDocumentEditor.Document) is the Header or Footer ?
I am in a scenario, where I dont want to do few operations when I am on footer. Could you help me in finding the active document that I am in is a Header or Footer ? 

Thanks 
Anand






0
Mihail
Telerik team
answered on 18 Aug 2014, 08:55 AM
Hello Anand,

 In order to determine what will be edited with the ActiveDocumentEditor you could subscribe to the RadRichTextBox.ActiveDocumentEditorChanged event. The argument of this event ActiveDocumentEditorChangedEventArgs contains the property DocumentEditorType, which specifies the part of the edited document: Header, Footer, Comment etc.

Here is example: 
private void RadRichTextBox_ActiveDocumentEditorChanged(object sender, ActiveDocumentEditorChangedEventArgs e)
{
    if (e.DocumentEditorType == DocumentEditorType.Header)
    {
        MessageBox.Show("In Header");
    }
    else if (e.DocumentEditorType == DocumentEditorType.Footer)
    {
        MessageBox.Show("In Footer");
    }
}

I hope this information answer your question.

Regards,
Mihail
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Anand
Top achievements
Rank 1
answered on 19 Aug 2014, 08:32 AM
Hi Mihail, 

Thanks for the reply. That works fine and I found another way of getting it.
var presenter = (IDocumentEditorPresenterContainer)this.radRichTextBox;
presenter.HeaderFooterUIContext.IsHeaderFocused

Regards
A





Tags
RichTextBox
Asked by
Anand
Top achievements
Rank 1
Answers by
Anand
Top achievements
Rank 1
Mihail
Telerik team
Share this question
or