'Go to Line' in a RichTextBox

a) get the char index of the line by sending message EM_LINEINDEX
b) set the selection to that point in the control (or the whole line EM_LINELENGTH) with EM_SETSEL or Select(int index, int lenght)
 
I finally got round to trying this out (because I've been gone on holiday). What I really want to do is have an integer, and go to the line of the inputed integer. It's sort of like when you press ctrl+G in microsoft word, notepad, etc..
 
How about this:
When you get an integer, extract the line that matches this integer,
then use .IndexOf to find the location of this line within the textbox.

Or you can use an .IndexOf loop.
Code:
x is an integer, and LN is a copy of the integer that tells which line to go to
LN -= 1
x = 0
Do Until LN = 0
x = yourtext.IndexOf(Convert.ToChar(10), x)
Convert.ToChar(10) is supposed to be the linefeed.
LN -= 1
Go Back To The Do
 
Thanks a lot!

here is the code:

Visual Basic:
        LN = UserInput - 1 'you have to do this, otherwise it will select the next line
        X = 0
        Do
            X = txtMain.Text.IndexOfAny(System.Environment.NewLine, X + 1)
            LN -= 1
        Loop Until LN = 0
        txtMain.Select(X + 1, 0) 'do this so it doesn't select the end of the line before
 
Back
Top