PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
This content has been translated automatically. Click here to view the French version.
  • The RTF format
  • Edit control in RTF
  • Remarks
  • Supported RTF format
  • Defining the initial content of an RTF edit control
  • Writing into an RTF edit control through programming (by using the RTF attributes)
  • Using the text attributes in an edit control in RTF
  • Saving a text in an RTF file
  • Saving a text in RTF in an item of an HFSQL file
  • Performing a "Find/Replace" operation in an edit control in RTF
  • Handling the characters in an edit control in RTF
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
The RTF format
The RTF (Rich Text Format) is used to code the text and the graphics specifically in order to simplify their transfer from an application to another one.
The RTF is a "tagged" format. Indeed, specific tags are used to specify the style of each word, group of words or sentences found in the text in RTF.
WINDEV allows you to handle text in RTF via the "RTF format" option of edit controls and static controls.
Versions 16 and later
You can also use the RichEdit property to change the RTF type of a control programmatically.
New in version 16
You can also use the RichEdit property to change the RTF type of a control programmatically.
You can also use the RichEdit property to change the RTF type of a control programmatically.
  • If the text in RTF format is displayed in a control that does not support the RTF format, the tags will be displayed.
  • If the text in RTF format is displayed in a control that supports the RTF format, the tags will be automatically interpreted and the text will be formatted accordingly.
Remark: To use an edit control in RTF, the "RICHED20.DLL" file must be found on the current computer. In most cases, the "RICHED20.DLL" file is in the Windows system directory. If a later version of the RTF control is available on the computer (including the RTF 4.1 control installed with Windows XP Service Pack 1), this version is used.
Edit control in RTF
An RTF edit control is used to display a text in RTF format and to enter a text in RTF format.
When entering a text in an RTF control, this text is in RTF. This text contains all the tags required to format the RTF.

Remarks

  • You have the ability to display a formatting toolbar above the RTF control. This toolbar allows the user to easily format the RTF text entered. For more details, see RTF formatting toolbar.
  • For applications running on Windows Vista (or higher), it is possible to integrate the "Handwriting" option. This option allows the user to directly type the text in the control with the stylus or with the mouse.
  • If the same text is entered in a standard edit control and in an RTF edit control, the character string found in the RTF edit control will be longer than the string found in the standard edit control (because the RTF tags are added).
  • The RTF edit control supports basic RTF formatting, so it can be used on any platform. The specific characters such as the page breaks, the notes, ... are not supported.

Supported RTF format

The format of the RTF files supported is the same RTF format as the one supported by "Wordpad" (up to Windows XP).
If the RTF file is generated by another tool (Word, ...), we advise you to open the file in Wordpad in order 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 the format of RTF.
Remark: You also have the ability to force the RTF format with WINDEV or WEBDEV. To do so, RTFLoad must be used 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. Display the "Content" tab of the description of RTF edit control.
  2. Type the content of RTF control in the "Initial content" control. To format the text, display the formatting toolbar via the "RTF formatting toolbar" option found in the popup menu of "Initial content" control.
  3. Validate the description window.
To define the initial content of an RTF edit control (solution 2):
  1. Type your text and format it via any RTF editor (Word, WINDEV document editor, ...)
  2. Copy this text (Ctrl + C).
  3. Display the "Content" tab of the description of RTF edit control.
  4. Paste the RTF text. The text is displayed with its formatting.
Writing into an RTF edit control through programming (by using the RTF attributes)

Using the text attributes in an edit control in RTF

To use the text attributes in an edit control in RTF, you must:
  • 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 RTFSelection. This function is used to find out and modify the RTF attributes (bold, ...) of a selection.
Example: Applying the bold attribute to the selected text
The following code, placed in the exit code of an RTF edit control, is used to apply the bold attribute to the selected text.
IF SAI_Saisie1.FinCurseur > SAI_Saisie1.Curseur THEN
RTFSélection(SAI_Saisie1, rtfBold, True)
END
Saving a text in an RTF file
In an RTF edit control, the text is automatically entered in RTF format.
To save the content of an edit control in RTF in a RTF file, you must:
  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 the edit control named TEXT_RTF.
sNomfic is string
sMaChaîne is string
nIDFic is int
sNomfic = fSelect("", "", "Sélectionnez un fichier...", ...
"Fichiers RTF" + TAB + "*.RTF" + CR + "Tous fichiers (*.*)" + TAB + "*.*", ...
"RTF", fselCreate + fselExist)
nIDFic = fOpen(sNomfic, foCreateIfNotExist + foAdd + foReadWrite)
IF nIDFic = -1 THEN
Error("L'ouverture du fichier a échoué")
ELSE
// On remplit la chaîne à écrire dans le fichier
sMaChaîne = SAI_Saisie1
// Ecriture du bloc
fWrite(nIDFic, sMaChaîne)
// Fermeture du fichier
fClose(nIDFic)
END

Saving a text in RTF in an item of an HFSQL file

To save a text in RTF format in a file item, we recommend you link the edit control to a Text Memo item.
Indeed, as the RTF format includes several tags, a "Character string" item is usually not large enough.
Performing a "Find/Replace" operation in an edit control in RTF
To perform a "Find/Replace" operation in a text in RTF:
  1. Use RTFSearch to find the requested text in the edit control in RTF format.
  2. Replace the text with RTFReplace.
Example: Finding WINDEV 5 and replacing it by WINDEV 19.
n is int
sMotRecherché is string = "WinDev 5"
sMotRemplace is string = "WinDev 19"
// Recherche case non sensitive, à partir de la fin de la sélection
n = RTFSearch(SAI_Saisie1, sMotRecherché)
// Si le mot est trouvé
IF n-1 THEN
// Remplace le mot trouvé
RTFReplace(SAI_Saisie1, sMotRemplace, n, n + Length(sMotRecherché))
END
Handling the characters in an edit control in RTF
WINDEV also allows you to handle the characters found in a string or in an RTF control. For example:
Example: Limiting/Truncating the number of characters found in a RTF string (excluding the RTF tags).
// Tronque le RTF au nombre de caractères indiqué dans nNbCaractereMax
nNbCaractereMax is int
nNbCaractereMax = 3
RTFReplace(SAI_Texte_RTF, "", nNbCaractereMax + 1, Length(SAI_Texte_RTF))
Example: Calculating the number of characters found in an RTF string (excluding the RTF tags).
// Récupère le contenu du RTF sans mise en forme
sUnicode is string UNICODE
nNbCaractere is int
 
sUnicode = RTFToText(SAI_Texte_RTF)
nNbCaractere = Length(sUnicode)
Info(nNbCaractere)
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.
Switching from the RTF format to the HTML format Unit examples (WINDEV): Switching from the RTF format to the HTML format
[ + ] Using RTFToHTML and RTFToText.
Minimum version required
  • Version 9
Comments
Click [Add] to post a comment