|
|
|
|
|
- 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
Handling RTF in an Edit control
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. 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): - Go to the "Content" tab of the RTF Edit control description.
- 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".
- Validate the description window.
To define the initial content of an RTF Edit control (solution 2): - Write the text and apply formatting in any RTF editor (Microsoft Word, WINDEV document editor, etc.).
- Copy this text (Ctrl + C).
- Go to the "Content" tab of the RTF Edit control description.
- 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: - Create the RTF file (fCreate) or open an existing RTF file (RTFLoad).
- 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
sMaChaîne = SAI_Saisie1
fWrite(nIDFic, sMaChaîne)
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: - Use RTFSearch to find the desired text in the RTF Edit control.
- 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"
n = RTFSearch(SAI_Saisie1, sMotRecherché)
IF n-1 THEN
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).
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).
sUnicode is string Unicode
nNbCaractere is int
sUnicode = RTFToText(SAI_Texte_RTF)
nNbCaractere = Length(sUnicode)
Info(nNbCaractere)
Related Examples:
|
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, ...)
|
|
Unit examples (WINDEV): The special characters
[ + ] Handling special characters in an RTF control and viewing the ASCII and ANSI codes.
|
|
Unit examples (WINDEV): Switching from the RTF format to the HTML format
[ + ] Using RTFToHTML and RTFToText.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|