Syntax 2 For RichTextEdit controls and presentation styles
Description
Selects text beginning and ending at a line and character
position in a RichTextEdit control.
Controls
RichTextEdit and DataWindow controls
Syntax
|
1 |
<span>rtename</span>.<span>SelectText</span> ( <span>fromline</span>, <span>fromchar</span>, <span>toline</span>, <span>tochar</span> { <span>band</span> } ) |
|
Argument |
Description |
|---|---|
|
rtename |
The name of the RichTextEdit or DataWindow |
|
fromline |
A long specifying the line number where |
|
fromchar |
A long specifying the number in the line |
|
toline |
A long specifying the line number where |
|
tochar |
A long specifying the number in the line |
|
band (optional) |
A value of the Band enumerated datatype
The default is the band that contains the insertion point. |
Return Values
Long. Returns the number of characters
selected. A carriage return with a line feed counts as a single
character. If an error occurs SelectText returns –1.
If any argument’s value is null, it
returns null.
Usage
The insertion point is at the “to” end of the selection, that
is, the position specified by toline and tochar.
If toline and tochar are
before fromline and fromchar,
then the insertion point is at the beginning of the selection.
You cannot specify 0 for a character position when making
a selection.
You cannot always use the values returned by Position to
make a selection. Position can return a character
position of 0 when the insertion point is at the beginning of a
line.
To select an entire line, set the insertion point and call SelectTextLine.
To select the rest of a line, set the insertion point and call SelectText with
a character position greater than the line length.
Examples
This statement selects text from the first character
in the RichTextEdit control to the fourth character on the third
line:
|
1 |
rte_1.<span>SelectText</span>(1,1, 3,4) |
This statement sets the insertion point at the beginning
of line 2:
|
1 |
rte_1.<span>SelectText</span>(2,1, 0,0) |
This example sets the insertion point at the end
of line 2 by specifying a large number of characters. The selection
highlight extends past the end of the line:
|
1 |
rte_1.<span>SelectText</span>(2,999, 0,0) |
This example sets the insertion point at the end
of line 2 by finding out how long the line really is. The code moves
the insertion point to the beginning of the line, gets the length,
and then sets the insertion point at the end:
|
1 |
long ll_length |
|
1 |
//Make line 2 the current line |
|
1 |
rte_1.<span>SelectText</span>(2,1, 0,0) |
|
1 |
// Specify a position after the last character |
|
1 |
ll_length = rte_1.LineLength() + 1 |
|
1 |
// Set the insertion point at the end |
|
1 |
rte_1.<span>SelectText</span>(2,ll_length, 0,0) |
|
1 |
rte_1.SetFocus() |
This example selects the text from the insertion
point to the end of the current line. If the current line is the
last line, the reported line length is 1 greater than the number
of character you can select, so the code adjusts for it:
|
1 |
long ll_insertline, ll_insertchar |
|
1 |
long ll_line, ll_count |
|
1 |
// Get the insertion point |
|
1 |
rte_1.Position(ll_insertline, ll_insertchar) |
|
1 |
// Get the line number and line length |
|
1 |
ll_line = rte_1.SelectedLine() |
|
1 |
ll_count = rte_1.LineLength() |
|
1 |
// Line length includes the eof file character, |
|
1 |
// which can't be selected |
|
1 |
IF ll_line = rte_1.LineCount() THEN ll_count -= 1 |
|
1 |
// Select from the insertion point to the end of |
|
1 |
// line |
|
1 |
rte_1.<span>SelectText</span>(ll_insertline, ll_insertchar, & |
|
1 |
ll_line, ll_count) |