Using the C1Document Class

As we mentioned earlier, the C1RichTextBox provides a linear, flat view of the control content, while C1Document class exposes the document structure.

To illustrate the advantages of working directly with the document object, suppose you wanted to add some functionality to the previous sample: when the user presses the CTRL key, you want to capitalize the text in all paragraphs of type Heading2.

The object model exposed by the C1RichTextBox is not powerful enough to do this reliably. You would have to locate spans based on their formatting, which would be inefficient and unreliable (what if the user formatted some plain text with the same format used by Heading2?).

Using the C1Document object model, this task becomes trivial:

      Visual Basic

      C#

The code monitors the keyboard. When the user presses the CTRL key, it enumerates all Heading2 elements in the document and replaces their content with capitals.

Doing the same thing using the C1RichTextBox object model would require a lot more code and the result would not be as reliable.


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.