RicherTextBox .NET user control is an extension of the
RichTextBox control. It has integrated toolstrips with the most common formatting options - choosing fonts, font style (bold, underline, italic), text alignment, bullets, indentation, zooming in and out and searching and replacing. Each one of the tools in the toolstrip can be hidden or shown in design-time or by using the code. In addition to the toolstrip, most of the functionality is also combined in a context menu. It also contains
public methods for managing the format using code when the usage of the toolstrip is not appropriate. Save and load funcionality is also implemented. The
RicherTextBox control is ready-to-use and its basic usage is as easy as dragging it from the toolbox into the container.
The toolstrip of
The context menu of
Using the Code
This control should be used as any other user control - just drag-drop in a designer, or create a new instance using a code editor. The only thing you need to do is to add a reference to the DLL-file of the control or the whole project in your project's references and add a
using directive in your code file to the
Without any other code, the control will became available in its full capabilities. If you want to enable or disable some functionality, it can be done in design time using the properties in
Toolstrip items visibility and
Toolstrip single items visibility categories, or by setting them using C# code.
Here are some examples of hiding items in the toolstrip using code. Let's assume that the control is implemented in a form and its name is set to
Hiding a group of tools:
richerTextBox1.GroupAlignmentVisible = false;
HideToolstripItemsByGroup is declared as follows...
public void HideToolstripItemsByGroup
(RicherTextBoxToolStripGroups group, bool visible)
RicherTextBoxToolStripGroups is enumeration including the values:
public enum RicherTextBoxToolStripGroups
SaveAndLoad = 0x1,
FontNameAndSize = 0x2,
BoldUnderlineItalic = 0x4,
Alignment = 0x8,
FontColor = 0x10,
IndentationAndBullets = 0x20,
Insert = 0x40,
Zoom = 0x80
The values in
HideToolstripItemsByGroup's first parameter can be combined using the bitwise or operator (
This is what the control looks like after executing this code:
As you can see, the alignment buttons and the bold, italic, underline buttons are now hidden.
Using the Methods for Accessing Functionality (Examples)
Let's say you want to toggle the bold parameter of the selected text from the code, it is done in a very simple way:
Setting the size of the used font:
The same is used for all of the formatting functionality of the control.
If you don't want the save and load buttons visible (or, even if they're visible), you will probably want to access the text which the user has typed in the control. Two properties are supplied for this purpose:
Text is an overriding property which contains the text in the
RicherTextBox in plain-text format.
Rtf holds the text in rich-text format.
Both properties can be set and read, and the
Rtf property also has simple error protection: when a
string with invalid format is associated with it, instead of throwing
ArgumentException, the invalid text is simply set as plain-text format:
richTextBox1.Text = "This is an example of setting the text in a RicherTextBox";
richTextBox1.Rtf = "Test";
Searching and Replacing
All that you need is to show (or, not hide) the toolstrip for finding. All functionality of searching and replacing is integrated in the control.
- Version 1.0 - 16 March, 2008: First released version