Using SelStart and SelLength
Posted on 2006-11-24
I have a VB6 app in which I am trying to highlight the contents on a textbox. I am achieving this using the SelStart and SelLength methods however the cursor always ends up on the right hand side of the text.
The problem I have is that if the text is too long for the textbox you cannot see the beginning of the string. Is there any way to move the cursor to the left of the text after the highlight has taken place?
I have tried doing the SelLength before the SelStart which ends up with the cursor on the left but no text is highlighted.
The code I am using looks like this,
Private Sub highlightText(ByVal ctrlTextBox As TextBox)
On Error GoTo highlightText_Err
If Len(ctrlTextBox.Text) <> 0 Then
ctrlTextBox.SelStart = 0
ctrlTextBox.SelLength = Len(ctrlTextBox.Text)