TRichEdit5
Source: source/classes/triched5.prg
Inherits from: TControl
TRichEdit5 wraps the Windows RichEdit 5.0 control (RichEdit50W window class), providing
advanced rich text editing with support for RTF formatting, syntax highlighting, table
insertion, inline pictures, spell checking, printing, and PDF export. It is suitable for
building full-featured text editors and code editors within FiveWin applications.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
cFileName | Character | Loaded file name |
nRTFSize | Numeric | Maximum RTF text size limit |
lReadOnly | Logical | Read-only mode |
lHighlight | Logical | Enable syntax highlighting |
aKeywords1 | Array | First keyword set for syntax highlighting |
aKeywords2 | Array | Second keyword set for syntax highlighting |
lBar | Logical | Show built-in formatting toolbar |
oBar | Object | Built-in toolbar object |
lSpell | Logical | Enable spell checking |
nClrNumber | Numeric | Syntax color for numbers |
nClrString | Numeric | Syntax color for strings |
nClrComment | Numeric | Syntax color for comments |
nClrKey1 | Numeric | Syntax color for first keyword set |
nClrKey2 | Numeric | Syntax color for second keyword set |
Methods
| Method | Description |
|---|---|
New( nTop, nLeft, bSetGet, oWnd, nW, nH, oFont, lPixel, cMsg, lHScroll, lReadOnly, bWhen, bValid, bChanged, lDesign, lHighlight, cFileName, nRTFSize, lNoURL, lNoScroll, lNoBorder, nLeftMargin, lNew, lBar ) | Create a new TRichEdit5 control |
ReDefine( nId, ... ) | Redefine from dialog resource |
LoadRTF( cRTF, lTxt ) | Load RTF or plain text content |
SaveAsRTF() / cText( cText ) | Get or set the control content as text |
InsertTable( nRows, nCols ) | Insert a table at the cursor position |
InsertPicture5( cFile, nSizeX, nSizeY ) | Insert a picture from file |
InsertBitmap( hBitmap, nSizeX, nSizeY, lSpecial ) | Insert a bitmap handle |
SetBold() / SetItalic() / SetUnderline() / SetStrikeOut() | Toggle character formatting on selection |
SetTextColor( nRGB ) | Set text color on current selection only. CFM_COLOR mask preserves bold, italic, font, size. No selection → word under caret |
GetTextColor() | Get current text color from selection |
SetBkGndColor( nRGB ) | Set background color on current selection |
SetAlign( nAlign ) | Set paragraph alignment |
SetIndent( nIndent ) | Set paragraph indentation |
Find( cFind, lDown, lCase, lWord ) | Search for text in the document |
ReplaceAll( lUndo, cFind, lDown, lCase, lWord, lAll, cText, lMsg ) | Find and replace all occurrences |
Cut() / Copy() / Paste() / Undo() / ReDo() | Standard clipboard and undo operations |
SaveToPDF( cFile ) | Export document to PDF |
Print( cName ) | Print the document |
Preview( cName, lModal ) | Show print preview |
HighLightAllText() | Re-apply syntax highlighting to entire document |
ImportExcel( nOp, nH ) | Import Excel worksheet content |
ImportWord( nOp ) | Import Word document content |
ImportHtml( cFile ) | Import HTML file |
RtfBarEdit() | Show or manage the built-in formatting toolbar |
Colorize( nStart, nEnd, nColor ) | Apply color to a range of text |
GetSelection() / GetSel() / SetSel() / SetPos() | Selection and cursor position management |
GetZoom() / SetZoom( nNum, nDen ) | Zoom level control |
GetLine( nLine ) / GetRow() / GetCol() | Line and position query methods |
Example: Selection Color
#include "FiveWin.ch"
#include "RichEdi5.ch"
function Main()
local oWnd, oRich
local cText := "Select text and click Blue or Red."
DEFINE WINDOW oWnd TITLE "RichEdit5 Test" ;
FROM 0, 0 TO 520, 700 PIXEL
@ 5, 5 RICHEDIT5 oRich VAR cText SIZE 680, 420 PIXEL OF oWnd
@ 440, 10 BUTTON "Blue" SIZE 80, 30 PIXEL OF oWnd ;
ACTION oRich:SetTextColor( CLR_BLUE )
@ 440, 100 BUTTON "Red" SIZE 80, 30 PIXEL OF oWnd ;
ACTION oRich:SetTextColor( CLR_RED )
ACTIVATE WINDOW oWnd CENTERED ;
ON RESIZE ResizeCtrls( oWnd, oRich )
return nil
Full sample: samples\test\testchclr.prg — includes Bold/Italic toggle buttons proving formatting survives color changes, plus ON RESIZE layout.
Notes
- TRichEdit5 uses the RichEdit 5.0 (MsftEdit 5.0) control, which is available on Windows Vista and later. It provides significantly more features than the standard RichEdit control.
- SetTextColor applies color to the current selection only (SCF_WORD | SCF_SELECTION). It sets only CFM_COLOR, so bold, italic, underline, font face, and font size are all preserved. If no text is selected, the color is applied to the word under the caret.
- Syntax highlighting is controlled by
lHighlightand configured via theaKeywords1,aKeywords2arrays and thenClrNumber,nClrString,nClrComment,nClrKey1,nClrKey2color values. - The
lBarflag enables a built-in formatting toolbar with bold, italic, underline, font, size, color, alignment, and table buttons. - Use
cText(SETGET access) to get or set the plain text content, orLoadRTF()/SaveAsRTF()for RTF content. - Spell checking (
lSpell) highlights misspelled words with a red underline. - PDF export and print preview are built-in via
SaveToPDF()andPreview(). - The control supports drag-and-drop of files via the
EN_DROPFILESnotification.