Discussions

Textbox Text Manipulation

There are three major properties that could be used in order to manipulate each of the characters inside the textbox. Let us discuss each of the properties.

SELSTART

This property of the textbox controls the "I" bar cursor position inside the text box or the selection start. Let us assume the the text inside the textbox is "hello world". See the figure below.


The value of the selstart of the figure above is seven(7) since the counting of the position starts zero(0) before "h" and spaces are included. To be able to put the "I" bar between the two(2) letter "L", the command should be: (Assuming that the name of our textbox is textbox1)

 textbox1.selstart = 3


SELLENGTH

This property of the textbox set or specify the length of the selection (in characters) from the specified selstart. Let us see the figure below.


To be able to highlight the word "world" in the textbox, we need the following code below.

textbox1.selstart = 6
textbox1.selstart = 5

The code above tells the system that the start of the selection is before "w" or six(6) and the span of the selection is five(5) since we want to highlight the word "world" with five(5) characters.


SELTEXT

This property returns or sets the string containing the currently selected text or the highlighted text out of combining selstart and sellength. Therefore, the value of the seltext above is "world". See the figure below:


Let us assume the the first textbox name is textbox1 and the second one is textbox2. Here is the code to do the output of the figure above.

textbox1.selstart = 4
textbox1.sellength = 5
textbox2.text = textbox1.seltext

The sellength is five(5) since the counting of the characters from the set selstart includes spaces. No seltext is return if either no seltext or sellength is specified.