Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need the correct text line / position from a text box.

Using e.Location.Y of the mouse position works for all lines but not for the last line at the bottom of the text box.

The text box has scrollbars.
If the last line at the bottom of the text box is only shown partial, then on mouse click the text box scrolls a little to show the last line complete.

Then the e.Location.Y value is wrong.

What I have tried:

I used

If SplitContainer11.SplitterDistance - e.Location.Y < 30 Then
'do this
Else
'do that
End If

but this helps not really.

What else can I try?
Posted
Comments
CHill60 12-Apr-21 12:38pm    
Why do you need the Y value rather than the relative position within the text box?
Jo_vb.net 12-Apr-21 13:15pm    
What I really need is the correct line in the textbox.

Private Function LineSelectionLogReviewRTF_Click(ByVal sender As Object, ByVal e As MouseEventArgs) _
Handles txtOutRichTextBox.MouseClick

Try

Dim index As Integer = txtOutRichTextBox.GetCharIndexFromPosition(e.Location)
Dim line As Integer = txtOutRichTextBox.GetLineFromCharIndex(index)

Inside the textbox is the content of a log.

If for example line 99 is last visible line above the horiz. scrollbar, the line value is 99 on mouseclick.

But if line 99 is not complete visible (a small part is already hidden by the scrollbar), then on mouseclick the line value is 100, because the textbox scrolls a little.

I used the Y value only for testing a workaround but that did not work as it should.
Jo_vb.net 18-Apr-21 8:45am    
Does really no one know a workaround for this issue?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900