Reputation: 2875
I'm trying to figure out if this is even possible. When someone clicks (or actually, double clicks) in my multi-line text box, I'd love to be able to figure out which of the lines[] items they double clicked on. I know I have the lines[] array as one of the properties of my windows forms textbox, and that's kind of cool, but when they double click is there anything that will tell me which index of that was under their mouse at the time?
Upvotes: 2
Views: 2152
Reputation: 941357
Use the GetCharIndexFromPosition() method to find the character that was clicked. Then GetLineFromCharIndex() to get the line that contains that characters. Like this:
Private Sub TextBox1_MouseDoubleClick(ByVal sender As Object, ByVal e As MouseEventArgs) Handles TextBox1.MouseDoubleClick
Dim pos = TextBox1.GetCharIndexFromPosition(e.Location)
Dim line = TextBox1.GetLineFromCharIndex(pos)
Debug.Print("You double-clicked line #{0}", line + 1)
End Sub
Upvotes: 7