PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
  • Rich Text Format
  • RTF Edit control
  • Remarks
  • Supported RTF
  • Defining the initial content of an RTF edit control
  • Writing in an RTF Edit control programmatically (via RTF attributes)
  • Using text attributes in an RTF Edit control
  • Saving text in an RTF file
  • Saving RTF text to an HFSQL data file item
  • Finding/Replacing text in an RTF Edit control
  • Handling characters in an RTF Edit control
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Rich Text Format
Rich Text Format (RTF) is used to encode text and simplify exchange between applications.
RTF is a "tag-based" format. In RTF, specific tags are used to specify the style of each word, group of words or sentences.
In WINDEV, you can handle RTF content via the "RTF" option of Edit and Static controls.
You can also use the RichEdit property to enable or disable RTF support for a given control.
  • If the RTF text is displayed in a control that does not support RTF, the tags will be displayed.
  • If the RTF content is displayed in a control that supports RTF, the tags will be automatically interpreted and the text will be formatted accordingly.
Remark: To use an RTF Edit control, the "RICHED20.DLL" file must be present on the current computer. In most cases, the "RICHED20.DLL" file is in the Windows system directory. If there is a more recent version of the RTF control on the computer, this version will be used.
RTF Edit control
The RTF Edit control is used to display and edit RTF content.
The control automatically stores entered text as RTF. This text will contain all the necessary formatting tags.

Remarks

  • An RTF toolbar can be displayed above the control. This toolbar allows the user to easily format the RTF text entered. For more details, see RTF formatting toolbar.
  • In applications running on Windows Vista (or later), you can include the "Handwritten input" option. This option allows the user to directly write in the control using the mouse or a stylus.
  • A given string will be longer in an RTF Edit control than in a standard Edit control, because RTF tags are added.
  • The RTF Edit control supports basic RTF, so it can be used on any platform. Specific characters such as page breaks, notes, ... are not supported.

Supported RTF

The RTF file format supported is the same as the one supported by Wordpad.
If the RTF file is generated by another tool (Word, etc.), it is recommended to open the file with Wordpad to check the RTF compatibility. The display of the file in Wordpad will provide a better preview of what will be printed.
In all cases, we recommend that you re-save the file in Wordpad to force RTF.
Remark: You also have the ability to force RTF with WINDEV or WEBDEV. To do so, use RTFLoad to assign the RTF control.
Defining the initial content of an RTF edit control
To define the initial content of an RTF Edit control (solution 1):
  1. Go to the "Content" tab of the RTF Edit control description.
  2. Type the content of the RTF control in "Initial content". To apply formatting to the text, display the formatting toolbar via the "RTF formatting toolbar" option in the context menu of "Initial content".
  3. Validate the description window.
To define the initial content of an RTF Edit control (solution 2):
  1. Write the text and apply formatting in any RTF editor (Microsoft Word, WINDEV document editor, etc.).
  2. Copy this text (Ctrl + C).
  3. Go to the "Content" tab of the RTF Edit control description.
  4. Paste the RTF content. The pasted text is displayed with its formatting.
Writing in an RTF Edit control programmatically (via RTF attributes)

Using text attributes in an RTF Edit control

To use text attributes in an RTF Edit control:
  • select the text in the Edit control. The text selected by the user is highlighted by default. To select text, you can use the Cursor and CursorEnd properties, for example.
  • use the RTFSelection function. This function allows you to get and set the RTF attributes (bold, etc.) of a selection.
Example: Applying bold formatting to the selected text
The following code, which is used in the exit code of an RTF edit control, applies bold formatting to the selected text.
IF EDT_Edit1.CursorEnd > EDT_Edit1.Cursor THEN
RTFSélection(EDT_Edit1, rtfBold, True)
END
Saving text in an RTF file
RTF formatting is automatically applied to the text entered in an RTF Edit control.
To save the content of an RTF Edit control to an RTF file:
  1. Create the RTF file (fCreate) or open an existing RTF file (RTFLoad).
  2. Copy the content of the RTF file into the current file (fWrite).
Example: Creating a "MyDoc.RTF" file. This file contains the text entered in RTF_TEXT Edit control.
sFileName is string
sMyString is string
nFileID is int
sFileName = fSelect("", "", "Select a file...", ...
"RTF files" + TAB + "*.RTF" + CR + "All files (*.*)" + TAB + "*.*", ...
"RTF", fselCreate + fselExist)
nFileID = fOpen(sFileName, foCreateIfNotExist + foAdd + foReadWrite)
IF nFileID = -1 THEN
Error("Cannot open the file")
ELSE
// Fill the string to write into the file
sMyString = EDT_Edit1
// Write the block
fWrite(nFileID, sMyString)
// Close the file
fClose(nFileID)
END

Saving RTF text to an HFSQL data file item

To save RTF text to an item of a data file, it is recommended to bind the Edit control to a Text Memo item.
As RTF includes many tags, "Character string" items are often too small.
Finding/Replacing text in an RTF Edit control
To find and replace RTF content:
  1. Use RTFSearch to find the desired text in the RTF Edit control.
  2. Replace the text with RTFReplace.
Example: Find "WinDev 19" and replace with "WinDev 28".
n is int
sSoughtWord is string = "WinDev 19"
sReplaceWord is string = "WinDev 28"
// Case-insensitive search, starting from the end of selection
n = RTFSearch(EDT_Edit1, sSoughtWord)
// If the word is found
IF n-1 THEN
// Replaces the word found
RTFReplace(EDT_Edit1, sReplaceWord, n, n + Length(sSoughtWord))
END
Handling characters in an RTF Edit control
WINDEV also allows you to handle the characters in a string or in an RTF control. For example:
Example: Limiting/Truncating the number of characters in an RTF string (excluding RTF tags).
// Limits the RTF content to the number of characters specified in MaxNbChar
nMaxNbCharacters is int
nMaxNbCharacters = 3
RTFReplace(EDT_RTF_Text, "", nMaxNbCharacters + 1, Length(EDT_RTF_Text))
Example: Calculating the number of characters in an RTF string (excluding RTF tags).
// Retrieves the RTF content without formatting
sUnicode is UNICODE string
nNbCharacters is int
 
sUnicode = RTFToText(EDT_RTF_Text)
nNbCharacters = Length(sUnicode)
Info(nNbCharacters)
Related Examples:
Management of RTF Unit examples (WINDEV): Management of RTF
[ + ] Using the main functions for RTF management in a WINDEV application:
- Load a file in RTF format
- Save a file in RTF format
- Find and select a word in an RTF text
- Display a text in RTF format
- Modify the characteristics of a selection (font, case, color, ...)
The special characters Unit examples (WINDEV): The special characters
[ + ] Handling special characters in an RTF control and viewing the ASCII and ANSI codes.
Minimum version required
  • Version 9
Comments
Click [Add] to post a comment