Determining the Lines as They Are Being Displayed in a TextBox Control
The TextBoxBase class provides a GetLines method which returns the textbox’ lines which are separated by a new line character sequence. However, textbox controls do not have a built-in method to get the lines as they are being displayed in the control including wrapped lines. This can be achieved using P/Invoke together with the SendMessage function as shown in the listing below. The functionality is encapsulated in the GetTextBoxLines function:
The listing below demonstrates how to determine the lines of a richtextbox control and add them to a listbox control: