This site has a good article about using the API to get line #, line text, # of lines in a textbox, etc. It's called Extending The TextBox Control. The API calls will work with a RichTextBox also.