471,319 Members | 1,411 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Position of the scroll in a TextBox

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
Jan 14 '06 #1
3 6630
On Sat, 14 Jan 2006 20:10:44 GMT, "Fabio Cannizzo"
<fc*****************@london.edu> wrote:
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
--

The ultimate truth is that there is no ultimate truth
Jan 14 '06 #2
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
"rossum" <ro******@coldmail.com> wrote in message
news:5p********************************@4ax.com...
On Sat, 14 Jan 2006 20:10:44 GMT, "Fabio Cannizzo"
<fc*****************@london.edu> wrote:
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
--

The ultimate truth is that there is no ultimate truth

Jan 16 '06 #3
On Mon, 16 Jan 2006 00:22:25 GMT, "Fabio Cannizzo"
<fc*****************@london.edu> wrote:
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

--

The ultimate truth is that there is no ultimate truth
Jan 16 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Boniface Frederic | last post: by
2 posts views Thread by GrantS | last post: by
4 posts views Thread by ojorus | last post: by
1 post views Thread by JC | last post: by
6 posts views Thread by Colin McGuire | last post: by
7 posts views Thread by Lit | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.