How to prevent editing of TextBox before certain position?

keypress, string, textbox, vb6

Solution

You can use a single-line `RichTextBox` and protect the prefix like this

Private Sub Form_Load()
    Const STR_PREFIX = "Example Text: "

    RichTextBox1.Text = STR_PREFIX & "The black cat."
    RichTextBox1.SelStart = 0
    RichTextBox1.SelLength = Len(STR_PREFIX)
    RichTextBox1.SelProtected = True
    RichTextBox1.SelLength = 0
End Sub

Problem

How can a `TextBox` be prevented from being edited before a given position? For example, if a `TextBox` contains the string: Example Text: The black cat. How can I prevent the user from editing anything before `"The"`? I can try to trap the `Backspace` key with the `KeyPress` event, but how can I use `MouseClick` to prevent the user from moving the cursor to a position before `"The"`.

Original source