TextRTF, SelRTF Properties

Purpose

Returns or sets (selection of) the text of a RichEdit control, including all .rtf code.

Syntax

RichEdit.TextRTF [= string]

RichEdit.SelRTF [= string]

Description

TextRTF returns or sets the text (in .rtf format).

SelRTF returns or sets the text (in .rtf format) in the current selection. SelText returns or sets plain text. Setting new selected text sets SelLength to 0 and replaces the selected text with the new string.

Example

Global Int32 rdpos

Ocx RichEdit red = "", 10, 10, 200, 200 : .MultiLine = True : .BorderStyle = 1

Ocx Command cmd1 = "Change Font", 230, 10, 140, 22

Ocx Command cmd2 = "Change Colour", 230, 40, 140, 22

Ocx Option opt(0) = "Subscript", 230, 70, 120, 14

Ocx Option opt(1) = "Normal", 230, 85, 120, 14 : opt(1).Value = 1

Ocx Option opt(2) = "Superscript", 230, 100, 120, 14

Ocx Command cmd3 = "Save Selection to File", 230, 130, 140, 22

Ocx Command cmd4 = "Save Whole Text to File", 230, 160, 140, 22

red.SetFocus

Do : Sleep : Until Me Is Nothing

If Exist(App.Path & "\AllText.rtf") Then Kill App.Path & "\AllText.rtf"

If Exist(App.Path & "\Select.rtf") Then Kill App.Path & "\Select.rtf"

 

Sub cmd1_Click

Ocx CommDlg cd

cd.Flags = cdfBoth

cd.ShowFont

With red

.SelFontName = cd.FontName

.SelFontSize = cd.FontSize

.SelBold = cd.FontBold

.SelItalic = cd.FontItalic

.SelStrikeout = cd.FontStrikethru

.SelUnderline = cd.FontUnderline

End With

red.SetFocus

EndSub

 

Sub cmd2_Click

Ocx CommDlg cd

cd.Flags = cdcFullOpen | cdcRgbInit

cd.Color = red.SelColor

cd.ShowColor

red.SelColor = cd.Color

red.SetFocus

EndSub

 

Sub cmd3_Click

If red.SelLength = 0 Then Message "No text has been selected"  : Exit Sub

Local t$ = red.SelRTF : BSave App.Path & "\Select.rtf", V:t$, Len(t$)

Message "Selected text saved as Select.rtf"

EndSub

 

Sub cmd4_Click

Local t$ = red.TextRTF : BSave App.Path & "\AllText.rtf", V:t$, Len(t$)

Message "Selected text saved as AllText.rtf"

EndSub

 

Sub opt_Click(Index%)

red.SelCharOffset = 90 * (Index% - 1)

red.SetFocus

EndSub

 

Sub red_GotFocus

red.SelStart = rdpos

EndSub

 

Sub red_LostFocus

If Not red Is Nothing Then rdpos = red.SelStart

EndSub

Remarks

You can use the TextRTF and SelRTF properties along with Open/Print # to write .rtf files.

See Also

RichEdit

{Created by Sjouke Hamstra; Last updated: 25/10/2014 by James Gaite}