First, you need the following declarations:
Private Const EM_GETLINECOUNT As Integer = &HBA
Private Const EM_GETLINE As Integer = &HC4
Private Const EM_LINELENGTH As Integer = &HC1
Private Const EM_LINEINDEX As Integer = &HBB
Private Declare Function SendMessageINT Lib "user32.dll" _
Alias "SendMessageA" (ByVal hWnd As IntPtr, _
ByVal wMsg As Integer, ByVal wParam As Integer, _
ByVal lParam As IntPtr) As Integer
Now, I placed this code in a button click event :
Counterset = 1 to start from second line.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim LineCount As Integer = SendMessageINT(TextBox1.Handle, EM_GETLINECOUNT, 0, IntPtr.Zero)
Dim counter As Integer = 0
Dim LineIndex As Integer = 0
Dim lineLength As Integer
Dim curLine As String = ""
Dim stringPTR As IntPtr
For counter = 1 To LineCount - 1
'Get Index for line we want to retrieve
LineIndex = SendMessageINT(TextBox1.Handle, EM_LINEINDEX, counter, IntPtr.Zero)
'GetLineLength
lineLength = SendMessageINT(TextBox1.Handle, EM_LINELENGTH, LineIndex, IntPtr.Zero)
'Create the buffer
curLine = New String("0"c, lineLength + 2)
Mid(curLine, 1, 1) = Chr(lineLength And &HFF)
Mid(curLine, 2, 1) = Chr(lineLength \ &H100)
'Get the pointer for a buffer
stringPTR = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(curLine)
'Fill the pointer with the current line
SendMessageINT(TextBox1.Handle, EM_GETLINE, counter, stringPTR)
'Read the line
curLine = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(stringPTR)
curLine = curLine.Substring(0, lineLength)
'fill textbox2
TextBox2.Text = TextBox2.Text + curLine + vbCrLf
'clear out the space
System.Runtime.InteropServices.Marshal.FreeHGlobal(stringPTR)
stringPTR = IntPtr.Zero
Next
End Sub
See the pic
Jx_Man
Nearly a Senior Poster
3,328 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444