TRichEdit
Description
Provides a wrapper for a Windows rich text edit control.
Remarks
Use a TRichEdit object to put a standard Windows rich text (RTF) edit control on a form. Rich text edit controls let the user enter text that includes variation in font attributes and paragraph formatting information.
TRichEdit Properties
You can use all properties from TEdit and TMemo. The following TRichEdit-specific properties are available as well:
Property HideScrollBars: Boolean (R/W)
Determines whether the scroll bars disappear when not needed. Use HideScrollBars to determine whether the scroll bars disappear from the edit control when the text appears completely within the edit window. Set HideScrollBars to false to prevent the scroll bars from flashing on and off when the contents of the rich edit control change. HideScrollBars does nothing when the ScrollBars property is set to ssNone (The default for TRichEdit).
Property PlainText: Boolean (R/W)
Controls whether the rich edit control treats the text as plain text or rich text when streaming to or from a file. To write the rich text in the control to a plain text file, set PlainText to true before streaming the text to a file. To ignore the rich text information encoded in a file, set PlainText to true before streaming the text to the control. To stream in the rich text attributes encoded in a file, or save the encoding of the rich text attributes to a file, set PlainText to false.
Property SelAttributes: TTextAttributes (R/W)
Use SelAttributes to discover or set the font characteristics of the currently selected text. SelAttributes specifies characteristics such as font face, color, size, style, and pitch. To change a single attribute of the currently selected text, read SelAttributes, and set one of its properties. To change all of the attributes of the currently selected text, set SelAttributes to a TTextAttributes object that represents the desired configuration of attributes. If no text is selected, SelAttributes represents the attributes of the cursor position.
When inserting new text, the font characteristics of the new text will match SelAttributes.
Code Snippet:
Sub
Button1Click(Sender)
with
RichEdit1.SelAttributes
.Color = vbRed
.Height = .Height + 5
RichEdit1.Lines.
Add
(
"This line of text will be red."
)
end with
End Sub
Property DefAttributes: TTextAttributes (R/W)
Use DefAttributes to discover or set the default font characteristics that the rich edit control uses for newly inserted text. These are the characteristics of the text before any special attributes have been applied. Once any special attributes are applied to a portion of text, no text from that point on is considered to have the default attributes, even if the attributes match the DefAttributes.
For example, if a rich edit control has had no attributes applied, the entire text has the default attributes. Selecting a portion of text in the middle and applying a specific attribute (such as a font change) results in three sections: a first section with the default attributes, a middle section with the applied attribute, and a final section with a non-default set of attributes that match the default attributes. Changing the DefAttributes property affects only the first section.
When inserting new text, the font characteristics of the new text will match the font characteristics at the cursor position, or, if the typing replaces a selection, the font characteristics of the selected text. New text will only have the default attributes when typed into the section of text that has the default attributes.
Code Snippet:
Sub
Button2Click(Sender)
RichEdit1.DefAttributes.Color = vbBlue
RichEdit1.DefAttributes.Style =
"fsBold, fsItalic"
End Sub
Property Paragraph: TParaAttributes (R/W)
Read Paragraph to get the TParaAttributes object used by the rich edit control to specify paragraph formatting information. Use the TParaAttributes object to read or write the paragraph formatting information for the current paragraphs. Paragraph formatting information includes alignment, indentation, numbering, and tabs.
Paragraph is a read-only property, because a TCustomRichEdit object has only one TParaAttributes object, which cannot be changed. The attributes of the current paragraphs, however, can be changed, by setting the properties of the TParaAttributes object.
The current paragraphs are the paragraphs that contain the selected text. If no text is selected, the current paragraph is the one containing the cursor.
Code Snippet:
Sub
Button3Click(Sender)
RichEdit1.Lines.
Clear
RichEdit1.Paragraph.Numbering =
1
rem nsBullet
RichEdit1.Lines.
Add
(
"Introduction"
)
RichEdit1.Lines.
Add
(
"New members to our team"
)
RichEdit1.Lines.
Add
(
"New Budget discussion"
)
RichEdit1.Lines.
Add
(
"Facilities"
)
RichEdit1.Lines.
Add
(
"Q & A"
)
RichEdit1.Paragraph.Numbering =
0
rem nsNone
RichEdit1.Paragraph.Alignment =
2
rem taCenter
RichEdit1.Lines.
Add
(
""
)
RichEdit1.Lines.
Add
(
"Suggested Topics:"
)
RichEdit1.Lines.
Add
(
""
)
RichEdit1.Paragraph.Alignment =
0
rem taLeftJustify
RichEdit1.Paragraph.FirstIndent =
10
RichEdit1.Lines.
Add
(
""
)
RichEdit1.Lines.
Add
(
"Parking lot repair"
)
RichEdit1.Lines.
Add
(
"Cost overruns"
)
End Sub