ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / Developing an application or website / Controls, windows and pages / Controls: Available types / Edit control
  • 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
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
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 manipulate RTF content via the "RTF" option of Edit and Static Text 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 edit control in RTF format, the file "RICHED20.DLL" must be present on the current workstation.. 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, etc. are not managed.

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. Wordpad will provide a more realistic print preview.
In all cases, we recommend that you re-save the file in Wordpad to force RTF.
Remark: It is also possible to force the RTF format directly 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 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 the RTFSelection function. This function allows you to get and set the RTF attributes (bold, etc.) of a selection.
Example: Make the selected text bold
The following code, which is used in the exit event of an RTF Edit control, applies bold formatting to the selected text.
IF SAI_Saisie1.FinCurseur > SAI_Saisie1.Curseur THEN
	RTFSelection(SAI_Saisie1, 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 to the current file (fWrite).
Example: Creating a "MonDoc.RTF" file. This file contains the text entered in RTF_TEXT Edit control.
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, foCreateIfNotFound + 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 RTF text to an HFSQL data file item

To save RTF text to a data file item, 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 perform a Search/Replace operation in an RTF text:
  1. Use RTFSearch to find the desired text in the RTF Edit control.
  2. Replace the text with RTFReplace.
Example: Search for the word WINDEV 19 and replace with WINDEV 28.
n is int
sMotRecherché is string = "WinDev 19"
sMotRemplace is string = "WinDev 28"
// 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 characters in an RTF Edit control
WINDEV also allows you to handle the characters in a string or in an RTF control. Some examples:
Example: Limit/truncate the number of characters contained in an RTF string (excluding 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: Calculate the number of characters in an RTF string (excluding 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

Last update: 09/21/2024

Send a report | Local help