View Single Post
Join Date: Nov 2007
Posts: 2,640
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Removing First Line Of Text From multiline textbox

 
0
  #2
Aug 26th, 2008
First, you need the following declarations:

  1. Private Const EM_GETLINECOUNT As Integer = &HBA
  2. Private Const EM_GETLINE As Integer = &HC4
  3. Private Const EM_LINELENGTH As Integer = &HC1
  4. Private Const EM_LINEINDEX As Integer = &HBB
  5.  
  6. Private Declare Function SendMessageINT Lib "user32.dll" _
  7. Alias "SendMessageA" (ByVal hWnd As IntPtr, _
  8. ByVal wMsg As Integer, ByVal wParam As Integer, _
  9. ByVal lParam As IntPtr) As Integer

Now, I placed this code in a button click event :
Counter set = 1 to start from second line.

  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. Dim LineCount As Integer = SendMessageINT(TextBox1.Handle, EM_GETLINECOUNT, 0, IntPtr.Zero)
  3. Dim counter As Integer = 0
  4. Dim LineIndex As Integer = 0
  5. Dim lineLength As Integer
  6. Dim curLine As String = ""
  7. Dim stringPTR As IntPtr
  8.  
  9. For counter = 1 To LineCount - 1
  10. 'Get Index for line we want to retrieve
  11. LineIndex = SendMessageINT(TextBox1.Handle, EM_LINEINDEX, counter, IntPtr.Zero)
  12. 'GetLineLength
  13. lineLength = SendMessageINT(TextBox1.Handle, EM_LINELENGTH, LineIndex, IntPtr.Zero)
  14. 'Create the buffer
  15. curLine = New String("0"c, lineLength + 2)
  16. Mid(curLine, 1, 1) = Chr(lineLength And &HFF)
  17. Mid(curLine, 2, 1) = Chr(lineLength \ &H100)
  18. 'Get the pointer for a buffer
  19. stringPTR = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(curLine)
  20. 'Fill the pointer with the current line
  21. SendMessageINT(TextBox1.Handle, EM_GETLINE, counter, stringPTR)
  22. 'Read the line
  23. curLine = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(stringPTR)
  24. curLine = curLine.Substring(0, lineLength)
  25. 'fill textbox2
  26. TextBox2.Text = TextBox2.Text + curLine + vbCrLf
  27. 'clear out the space
  28. System.Runtime.InteropServices.Marshal.FreeHGlobal(stringPTR)
  29. stringPTR = IntPtr.Zero
  30. Next
  31.  
  32. End Sub

See the pic
Last edited by Jx_Man; Aug 26th, 2008 at 1:24 am.
Attached Thumbnails
multiline.JPG  
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote