C1RichTextBox Concepts and Main Properties

On the surface, the C1RichTextBox control appears just like a standard TextBox. It provides the same properties to control the font, colors, text, and selection. That can be an advantage – if you have an application that uses TextBox controls, you may be able to simply replace them with C1RichTextBox controls without any additional changes.

For example, the following code implements a simple search-and-replace routine that works on TextBox and on C1RichTextBox controls:

      Visual Basic

      C#

The code looks for matches in the Text property. It selects each match using the Selectmethod, and then replaces the text using the SelectedText property. To convert this method for use with the C1RichTextBox control, you would simply change the type of the first argument to use a C1RichTextBox instead of a regular TextBox.

This is what the C1RichTextBox has in common with the regular TextBox. But of course it goes way beyond that. Suppose you wanted to highlight the replacements with a yellow background. This would be impossible with a regular TextBox. With the C1RichTextBox, you could accomplish that with one additional line of code:

      Visual Basic

      C#

The Selection property provides properties that allow you to inspect and modify the formatting of the current selection. With this property and the ones in common with the TextBox control, you can easily create documents and add rich formatting.

You could use the technique described above to implement a toolbar or to add syntax coloring to documents. These topics are described in more detail in later sections.


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