Each range text element has a property called Range which allow you to get the range of positions spanned by a particular text element. For example, consider the following code:
Range |
Copy Code
|
---|---|
NSection section = new NSection(); NParagraph paragraph = new NParagraph(); NTextInline lowerCaps1 = new NTextInline("lower case text "); NTextInline upperCaps = new NTextInline("UPPER CASE TEXT"); NTextInline lowerCaps2 = new NTextInline(" lower case text"); paragraph.Inlines.Add(lowerCaps1); paragraph.Inlines.Add(upperCaps); paragraph.Inlines.Add(lowerCaps2); section.Blocks.Add(paragraph); m_RichText.Content.Sections.Clear(); m_RichText.Content.Sections.Add(section); m_RichText.Content.Selection.SelectRange(upperCaps.Range); |
Note that the last line of code selects the range spanned by the inline containing upper caps. This results in the following text output:
In this particular example, the value of the Range property of the upper caps inline is [16, 30]. This is because the inline element before it contains 16 characters and the upper caps inline itself is 15 chars long.
Blocks elements have ranges that encompass the content of all their descendant inline elements - for example, the Range property of the paragraph defined in the above example is [0, 47]. This is how it's calculated:
- lowerCaps1 - [0, 15]
- upperCaps - [16, 30]
- lowerCaps2 - [31, 46]
- paragraph end [47, 47]