tags:

views:

245

answers:

1

I have a rich text box where you can edit java code with a listbox on the side of it that has the line numbers. I want the listbox to scroll with the rich text box so that they line up. How would you get them to scroll as one?

+3  A: 

There is an MSDN entry on the GetLineFromCharIndex method on a RichTextBoxControl.

This in conjunction with the SelectionStart property should allow you to do something like this:

//This next line only indicates the caret position if no text is selected
Int32 caretPosition = richTextBox1.SelectionStart

Int32 lineNum = richTextBox1.GetLineFromCharIndex(caretPosition)
Josh
When i typed in the vb declaration it said that it could not be declared overrides because it does not override a function in a base class
muckdog12
I'm a little confused... were you trying to implement that member, or just use it. It is a member of RichTextBox, so you should be able to just call it on the instance of your RichTextBox control you are trying to use.
Josh
I have a rich text box where you can edit java code with a listbox on the side of it that has the line numbers. I want the listbox to scroll with the rich text box so that they line up. I just figured that getting the line number and setting the listbox's selectedindex to it would work. If you have another sugestion that would be great
muckdog12