However, i'll leave it to you to tweak the rest, a simple loop to add vbnewline at end of sentence and remove from the start should fix it.
2 boxes on the form. textbox1, textbox2. both have multiline set = true
Private Sub TextBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Click Dim mousepos As Long = TextBox1.SelectionStart Dim currentpos As Long = 0 Dim str As String() = TextBox1.Text.Split(New Char() {vbNewLine}) For i As Integer = 0 To str.GetUpperBound(0) If (str(i).Length + currentpos) > mousepos Then TextBox2.Text = "Row:" & i + 1 & " Clm:" & str(i).Length - (str(i).Length + currentpos - mousepos) Exit Sub Else currentpos += str(i).Length End If Next End Sub |
Private Function GetCursorPosition(ByVal target As TextBox) As Point Dim column As Integer = target.SelectionStart Dim row As Integer = 0 While column > target.Lines(row).Length 'Remove the length of the current line and account for carriage return and line feed. column -= target.Lines(row).Length + 2 'Advance to next line. row += 1 End While 'Return a Point object that represents (column, row). Return New Point(column, row) End Function |