Move Visible Portion of RichTextBox to Desired Line

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aemihal
    New Member
    • Apr 2007
    • 1

    Move Visible Portion of RichTextBox to Desired Line

    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.Se lectionStart = RichTextBox1.Ge tFirstCharIndex FromLine(123)
    RichTextBox1.Se lectionLength = 0
    RichTextBox1.Sc rollToCaret()

    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
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by aemihal
    ...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.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      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.

      Comment

      Working...