Private Sub TextBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Click
Dim txtHold As TextBox = CType(sender, TextBox)
For intBeg As Int32 = (txtHold.SelectionStart * -1) To 0
If Math.Abs(intBeg) = txtHold.Text.Length Then
'Beyond the length of the string, nothing selected.
ElseIf txtHold.Text.Substring(Math.Abs(intBeg), 1) = " " Then
txtHold.SelectionStart = Math.Abs(intBeg) + 1
txtHold.SelectionLength = selLen(txtHold, intBeg)
Exit For
ElseIf intBeg = 0 Then
txtHold.SelectionStart = intBeg
txtHold.SelectionLength = selLen(txtHold, intBeg)
End If
Next intBeg
End Sub
Private Function selLen(ByRef txtHold As TextBox, ByVal intBeg As Int32) As Int32
For intEnd As Int32 = txtHold.SelectionStart + 1 To txtHold.Text.Length
If txtHold.Text.Substring(intEnd, 1) = " " Then
Return (intEnd - txtHold.SelectionStart)
Exit For
ElseIf intEnd = txtHold.Text.Length - 1 Then
Return (intEnd - txtHold.SelectionStart + 1)
Exit For
End If
Next
End Function