Position of the scroll in a TextBox

  • Thread starter Thread starter Fabio Cannizzo
  • Start date Start date
F

Fabio Cannizzo

If a multiline text window is "scrolled", how can I get ho much it has been
scrolled from the begin of the document?

Thanks,
Fabio
 
If a multiline text window is "scrolled", how can I get ho much it has been
scrolled from the begin of the document?

Thanks,
Fabio

You can do this by lines or by characters.

1 Characters:

The total number of characters is myTextBox.Text.Length, the character
position at the start of the current line is
myTextBox.GetFirstCharIndexOfCurrentLine(). From those two you can
get an idea of where you are in the text.

2 Lines:

The total number of lines is myTextBox.Lines.Count. To find the
current line use GetFirstCharIndexOfCurrentLine() as above and then
use GetLineFromCharIndex(int charIndex) to find the current line.
Again this will give you an idea of where you are in the text.

The Object Browser is your friend in things like this.

rossum
 
Hi Rossum.

Thanks for your mail.

I think that GetFirstCharIndexOfCurrentLine() does not solve my problem.
Current line, is the line where the caret is located. However, if the text
has been scrolled using the default scrollbars, that could well be outside
the screen. I need to know the position of the screen window with respect to
my text document.

For instance, if I take the client coordinates (1,1), if there was a way to
know which character correspond to that position, that would do it.

Regards,
Fabio
 
For instance, if I take the client coordinates (1,1), if there was a way to
know which character correspond to that position, that would do it.

myTextBox.GetCharIndexFromPosition(System.Drawing.Point) returns the
integer character index of the character at a given position, in your
case (1, 1). This seems to be what you want.

rossum
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top