思路:获取鼠标点击后的光标位置,计算回车数量、回车开始的位置和下一个回车符号的位置,然后选中这行文本。
Private Sub textBox1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim 回车数量 As Integer = 0
Dim 已选中 As Boolean = False
Dim text As String = Me.textBox1.Text
Dim 回车位置 As Integer = 0
Dim 本行长度 As Integer = text.IndexOf(Microsoft.VisualBasic.Strings.ChrW(10))
For i As Integer = 0 To textBox1.SelectionStart - 1
If 已选中 Then
本行长度 = i - 回车位置 + 1
End If
If text(i) = Microsoft.VisualBasic.Strings.ChrW(10) Then
回车数量 += 1
回车位置 = i
已选中 = True
End If
Next
Me.Text = (回车数量 + 1).ToString()
textBox1.Select(回车位置, 本行长度)
End Sub