Rich Textbox Control


© Maxim Karetnikov
Articles in this Topic    Discussions in this Topic

RTF stands for rich text format; it was designed to create portable formatted documents that can be displayed on different systems. Like HTML,  RTF language uses tags to describe the document's format. For example, the sentence:

Rome was not built in a day

will look in RTF format in a following manner:

{\b\lang1033 Rome}{\lang1033 was }{\i\lang1033 not}{\lang1033 built }{\b\i\lang1033 in}{\lang1033 a day \par }

RTF, however, is much more complicated than HTML because RTF was meant to be used internally by applications. Just as you need a browser to view HTML documents, you need an RTF-capable application to view RTF documents. WordPad, for instance, supports RTF and can save a document in RTF format and read RTF files.

The Rich Textbox control has many properties, the most important of them being the ones that manipulate the selected text. All these properties start with the prefix Sel. SelText is the selected text. To assign the selected text to a variable, use the statement

SText=RichTextbox1.SelText

where RichTextbox1 is the name of the control. You can also modify the selected text by assigning a new value to the SelText property. The statement

RichTextbox1.SelText=UCase(RichTextbox1.SelText)

converts the selected text to uppercase. If you assign a string to the SelText property, the selected text in the control will be replaced. The statement

RichTextbox1.SelText="replacement string"

will replace the current selection on the RichTextbox1 control with the string "replacement string". If no text was selected, the same statement will insert the string at the location of the pointer. It is possible, therefore, to automatically insert text by assigning a string to the SelText property. This technique is quite useful in displaying some initial text on the control.

To simplify the manipulation and formatting of the text on the control, there are two additional properties, the SelStart and SelLength properties, which report the position of the first selected character in the text and the length of the selection respectively. You can also set the values of these properties to select a piece of text from within your code. One obvious use of these properties is to select (and highlight) the entire text:

RichTextBox1.SelStart=0
RichTextBox1.SelLength=Len(RichTextBox1.Text)

The Text property returns the text on the control, just like the Text property of the TextBox control.

The properties for formatting the selected text are SelBold, SelItalic, and SelUnderline. You can read the value of these properties to check the formatting of the selected text from within your code or set them to change the formatting accordingly. The statements

Go To Page: 1 2


Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo