By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,501 Members | 2,790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,501 IT Pros & Developers. It's quick & easy.

Move Visible Portion of RichTextBox to Desired Line

P: 1
Hello,

I have a RichTextBox that has a large number of lines, well in excess of the amount that can be seen without scrolling. Upon an event, such as clicking a button, I would like to move the viewable portion of the RichTextBox to be able to see that particular line. In other words, if the RichTextBox has 1000 lines of text, how can I force the viewable portion to start at, say, line number 123?

This is what I have tried so far:
RichTextBox1.SelectionStart = RichTextBox1.GetFirstCharIndexFromLine(123)
RichTextBox1.SelectionLength = 0
RichTextBox1.ScrollToCaret()

I pretty much know I am not setting the SelectionStart property to the right value, but I don't really understand what the SelectionStart property is referencing: line number, position in the file, etc. The help page says it gets or sets the starting point of text selected in the text box. What does it mean for text to be "selected"?
Thanks,

Andrew
Apr 10 '07 #1
Share this Question
Share on Google+
2 Replies


Expert 5K+
P: 8,434
...I pretty much know I am not setting the SelectionStart property to the right value, but I don't really understand what the SelectionStart property is referencing: line number, position in the file, etc. The help page says it gets or sets the starting point of text selected in the text box. What does it mean for text to be "selected"?
That would be "selected" like when you drag the mouse over the text, causing it to be highlighted with a blue (in my case) background. Like when you want to copy the text. If you set the selected length to 1 (or more) instead of zero, you should at least be able to see where your selection point is.
Apr 12 '07 #2

Expert 5K+
P: 8,434
Something else to consider. Are there actually 1,000 lines? Or are there a smaller number of long lines, wrapped around? There's probably a difference. Although I'm not familiar with the control in question, I would guess that it probably counts end-of-line delimiters. Or in other words, paragraph breaks (to use Word-speak).

However, I suspect your best line of attack will be to play with the selection properties to get a feel for them. Perhaps "reverse engineer" them by writing a simple event procedure to print them out as you manually change the selection.
Apr 12 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.