Syntax 2: For RichTextEdit controls and presentation
styles
Description
Selects text beginning and ending at a line and character position
in a RichTextEdit control.
Applies to
RichTextEdit and DataWindow controls
Syntax
|
1 |
rtename.SelectText ( fromline, fromchar, toline, tochar { band } ) |
|
Argument |
Description |
|---|---|
|
rtename |
The name of the RichTextEdit or DataWindow control in |
|
fromline |
A long specifying the line number where the selection |
|
fromchar |
A long specifying the number in the line of the first |
|
toline |
A long specifying the line number where the selection |
|
tochar |
A long specifying the number in the line of the |
|
band (optional) |
A value of the Band enumerated datatype specifying the
The default is the band that contains the insertion |
Return value
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.SelectText(1,1, 3,4) |
This statement sets the insertion point at the beginning of line
2:
|
1 |
rte_1.SelectText(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.SelectText(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 2 3 4 5 6 7 8 |
long ll_length //Make line 2 the current line rte_1.SelectText(2,1, 0,0) // Specify a position after the last character ll_length = rte_1.LineLength() + 1 // Set the insertion point at the end rte_1.SelectText(2,ll_length, 0,0) 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 2 3 4 5 6 7 8 9 10 11 12 13 14 |
long ll_insertline, ll_insertchar long ll_line, ll_count // Get the insertion point rte_1.Position(ll_insertline, ll_insertchar) // Get the line number and line length ll_line = rte_1.SelectedLine() ll_count = rte_1.LineLength() // Line length includes the eof file character, // which can't be selected IF ll_line = rte_1.LineCount() THEN ll_count -= 1 // Select from the insertion point to the end of // line rte_1.SelectText(ll_insertline, ll_insertchar, & ll_line, ll_count) |
See also