JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Rich Text Boxes

Want a full-fledged word processor in your application? Use a rich text box. Not only can you enter formatted text (selecting fonts, italics, bolding, and more) in a rich text box, you also can save that text in rich text format (RTF) files, and read RTF files in it. Commercial word processors like Microsoft Word can read RTF files, allowing you to interface to those word processors fully. (In fact, many people prefer RTF files these days because they cannot harbor macro viruses.)

We've discussed rich text boxes in the In Depth section of this chapter. Take a look at Tables 5.8, 5.9, and 5.10 to see the notable properties, methods, and events of the RichTextBox class. These tables do not include all the notable properties, methods, and events this class inherits from the Control class—you'll find them in Tables 5.1, 5.2, and 5.3.

Table 5.8: Noteworthy public properties of RichTextBox objects.

Property

Means

AutoSize

Sets/gets a value specifying if the size of the rich text box automatically adjusts when the font changes.

AutoWordSelection

Sets/gets a value specifying if automatic word selection is enabled.

BorderStyle

Sets/gets the border type of the rich text box.

BulletIndent

Sets/gets the indentation used in the rich text box when the bullet style is applied to the text.

CanRedo

Indicates if there were actions in rich text box that can be reapplied.

CanUndo

Returns a value specifying if the user can undo the previous operation in the rich text box.

DetectUrls

Sets/gets a value specifying if the rich text box should detect URLs when typed into the RichTextBox control.

HideSelection

Sets/gets a value specifying if the selected text should stay highlighted when the RichTextBox control loses focus.

Lines

Sets/gets the lines of text in a RichTextBox control.

MaxLength

Sets/gets the maximum number of characters the user can type into the rich text box.

Modified

Sets/gets a value that indicates that the RichTextBox control has been modified by the user since the Control was created or its contents were last set.

Multiline

Sets/gets a value specifying if this is a multiline RichTextBox control.

PreferredHeight

Gets the preferred height for a single-line rich text box.

ReadOnly

Sets/gets a value specifying if text in the rich text box is read-only.

RightMargin

Sets/gets the size of a single line of text within the RichTextBox control.

Rtf

Sets/gets the text of the RichTextBox control, including all rich text format (RTF) codes.

ScrollBars

Sets/gets the kind of scroll bars to display in the RichTextBox control.

SelectedRtf

Sets/gets the currently selected rich text format (RTF) formatted text in the control.

SelectedText

Sets/gets the selected text within the rich text box.

SelectionAlignment

Sets/gets the alignment to apply to the current selection or insertion point.

SelectionBullet

Sets/gets a value specifying if the bullet style is applied to the current selection or insertion point.

SelectionCharOffset

Sets/gets if text in the RichTextBox control appears on the baseline, as a superscript, or as a subscript.

SelectionColor

Sets/gets the text color of the current text selection or insertion point.

SelectionFont

Sets/gets the font of the current text selection or insertion point.

SelectionHangingIndent

Sets/gets the distance between the left edge of the first line of text in the selected paragraph and the left edge of the next lines in the same paragraph.

SelectionIndent

Sets/gets the distance in pixels between the left edge of the rich text box and the left edge of the current text selection or text added after the insertion point.

SelectionLength

Sets/gets the number of characters selected in control.

SelectionRightIndent

The distance in pixels between the right edge of the RichTextBox control and the right edge of the text that is selected.

SelectionStart

Sets/gets the starting point of text selected in the text box.

SelectionTabs

Sets/gets the absolute tab stop positions in a RichTextBox control.

Text

Sets/gets the current text in the rich text box.

TextLength

Gets the length of text in the RichTextBox control.

WordWrap

Indicates if a multiline RichTextBox control automatically wraps words.

ZoomFactor

Sets/gets the current zoom level of the rich text box.

Table 5.9: Noteworthy public methods of RichTextBox objects.

Method

Means

AppendText

Appends text to the current text of the rich text box.

CanPaste

Determines if you can paste information from the Clipboard.

Clear

Clears all text from the RichTextBox control.

ClearUndo

Clears information about the most recent operation from the undo buffer of the rich text box.

Copy

Copies the current selection in the rich text box to the Clipboard.

Cut

Moves the current selection in the rich text box to the Clipboard.

Find

Searches for text within the contents of the rich text box.

GetLineFromCharIndex

Gets the line number from the specified character position within the text of the RichTextBox control.

GetPositionFromCharIndex

Gets the location within the control at the specified character index.

LoadFile

Loads the contents of a file into the RichTextBox control.

Paste

Pastes the contents of the Clipboard into the RichTextBox control.

Redo

Reapplies the last operation that was undone in the RichTextBox control.

SaveFile

Saves the contents of the rich text box to a file.

ScrollToCaret

Scrolls the contents of the RichTextBox control to the current caret position.

Select

Selects text within the RichTextBox control.

SelectAll

Selects all text in the rich text box.

Undo

Undoes the last edit operation in the rich text box.

Table 5.10: Noteworthy public events of RichTextBox objects.

Event

Means

Click

Occurs when the rich text box is clicked.

LinkClicked

Occurs when the user clicks on a link within the text of the RichTextBox control.

ModifiedChanged

Occurs when the value of the Modified property is changed.

ReadOnlyChanged

Occurs when the value of the ReadOnly property is changed.

SelectionChanged

Occurs when the selection of text within the RichTextBox control is changed.

VScroll

Occurs when the user clicks the vertical scroll bars of the RichTextBox control.

Tip 

Now you can even use a RichTextBox for Web-style links by setting the DetectUrls property to True and writing code to handle the LinkClicked event.

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor