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 |
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: RTF Editor
#include "FiveWin.ch"
function Main()
local oWnd, oRE
DEFINE WINDOW oWnd TITLE "RichEdit 5.0 Editor" SIZE 800, 600
@ 10, 10 RICHEDIT5 oRE VAR "" ;
OF oWnd ;
SIZE 760, 540 ;
HIGHLIGHT ;
BAR ;
FILE "document.rtf"
ACTIVATE WINDOW oWnd CENTERED
return nil
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.
- 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.