Text for the control – PB Docs 2019

Text for the control

In the Window painter, you do not enter text in the control.
Instead, in your application you can programmatically insert text or let
the user enter text using the editing tools.

Setting a default font

The Font tab page in the Properties view for a RichTextEdit
control lets you set default font characteristics for the control.
When the control first displays at runtime, and you include the
toolbar with a RichTextEdit control, the toolbar indicates the default
font characteristics that you selected on the Font tab page at design
time. Although the application user can change fonts at runtime, or
you can use PowerScript to change the font style, you can set the
default font at design time only.

Inserting text

From a file

If you have prepared a text file for your application, you can
insert it with the InsertDocument function. The file can be rich text or
ASCII:

The boolean clearflag argument lets you specify whether to insert
the file into existing text or replace it. If you want to include
headers and footers from a document that you insert, you must replace
the existing text by setting the clearflag argument to TRUE. (The
InsertFile command on the runtime pop-up menu is equivalent to the
InsertDocument function with the clearflag argument set to
FALSE.)

DisplayOnly property must be set to false

You cannot insert a document into a rich text control when the
control’s DisplayOnly property is set to true. If you try to do this,
PowerBuilder displays a runtime error message.

From a database

If you have saved rich text as a string in a database, you can use
a DataStore to retrieve the text.

After retrieving data, paste the string into the RichTextEdit
control:

Rich text and the clipboard

The CopyRTF and PasteRTF functions let you get rich text with
formatting instructions and store it in a string. If you use the
clipboard by means of the Copy, Cut, and Paste functions, you get the
text only — the formatting is lost.

Example of saving rich text in a
database

Suppose you have a database table that records tech support calls.
Various fields record each call’s date, support engineer, and customer.
Another field stores notes about the call. You can let the user record
notes with bold and italic formatting for emphasis by storing rich text
instead of plain text.

The window for editing call information includes these
controls:

  • A DataWindow control that retrieves all the data and displays
    everything except the call notes

  • A RichTextEdit control that displays the call notes

  • A button for updating the database

RowFocusChanged event

As row focus changes, the notes for the current row are pasted
into the RichTextEdit control. The RowFocusChanged event has this
script:

LoseFocus event

When the user makes changes, the changes are transferred to the
DataWindow control. It is assumed that the user will click on the button
or the DataWindow control when the user is through editing, triggering
the LoseFocus event, which has this script:

LoseFocus and the toolbars

A LoseFocus event occurs for the RichTextEdit control even when
the user clicks a RichTextEdit toolbar. Technically, this is because
the toolbars are in their own windows. However, the RichTextEdit
control still has focus, which you can check with the GetFocus
function.

Saving rich text in a file

You can save the rich text in the control, with the input field
definitions, with the SaveDocument function. You have the choice of rich
text format (RTF) or ASCII:

SaveDocument does not save the data in the input fields. It saves
the document template.

Does the file exist?

If the file exists, calling SaveDocument triggers the FileExists
event. In the event script, you might ask users if they want to
overwrite the file.

To cancel the saving process, specify a return code of 1 in the
event script.

Are there changes that need saving?

The Modified property indicates whether any changes have been made
to the contents of the control. It indicates that the contents are in an
unsaved state. When the first change occurs, PowerBuilder triggers the
Modified event and sets the Modified property to TRUE. Calling
SaveDocument sets Modified to FALSE, indicating that the document is
clean.

Opening a file triggers the Modified event and sets the property
because the control’s contents changed. Usually, though, what you really
want to know is whether the contents of the control still correspond to
the contents of the file. Therefore, in the script that opens the file,
you can set the Modified property to FALSE yourself. Then when the user
begins editing, the Modified event is triggered again and the property
is reset to TRUE.


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x