none
remember cursor position text box RRS feed

  • Question

  • i have a text box where the user can insert text by choosing lines in a listbox.

    now , i want to put the lines at the position where the cursor was in that textbox

    so i need to remember where the cursor was , how is that done ?

    Monday, May 23, 2016 11:16 AM

Answers

  • A text box has properties SelStart and SelLength.

    SelStart is the zero-based position of the beginning of the selected text, and SelStart is the length of the selected text. If no text is selected, SelLength = 0.

    You can only read and set these properties when the text box has the focus. So you should assign SelStart to a variable before the user clicks in the list box, for example in the On Exit or On Lost Focus event of the text box:

    Public lngStart As Long

    Private Sub Text0_LostFocus()
        lngStart = Me.Text0.SelStart
    End Sub

    Then later on, you can set the SelStart property:

        Me.Text0.SelStart = lngStart


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Proposed as answer by André Santo Monday, May 23, 2016 1:13 PM
    • Marked as answer by tekoko10 Monday, May 23, 2016 1:19 PM
    Monday, May 23, 2016 11:42 AM