|
-
Jan 6th, 2007, 12:22 AM
#1
Delete Line
Dear All,
How to remove a line from the richtextbox, by passing the line number in API Sendmessage?
Please mark you thread resolved using the Thread Tools as shown
-
Jan 6th, 2007, 01:21 AM
#2
Re: Delete Line
Here's something from the API guide that I modified to do what you want.
VB Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long
Private Const EM_GETLINE = &HC4
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_LINEINDEX = &HBB
Private Const EM_LINELENGTH = &HC1
Private Sub Command1_Click()
Dim lngCount As Long
Dim lngLineIndex As Long
Dim lngLength As Long
Dim strBuffer As String
Dim strRichText As String
Dim i As Integer
'Get Line count
lngCount = SendMessage(RichTextBox1.hwnd, EM_GETLINECOUNT, 0, 0)
With RichTextBox1
For i = 0 To lngCount - 1
If i <> 1 Then ' If you wanted to get rid of the second line
'Get line index
lngLineIndex = SendMessage(.hwnd, EM_LINEINDEX, i, 0)
'get line length
lngLength = SendMessage(.hwnd, EM_LINELENGTH, lngLineIndex, 0)
'resize buffer
strBuffer = Space(lngLength)
'get line text
Call SendMessageStr(.hwnd, EM_GETLINE, i, ByVal strBuffer)
'Accumulate the text to be kept
strRichText = strRichText & strBuffer & vbCrLf
End If
Next
'rewrite text in RichTextBox
.Text = strRichText
End With
End Sub
Last edited by MartinLiss; Jan 6th, 2007 at 01:25 AM.
-
Jan 6th, 2007, 01:30 AM
#3
Re: Delete Line
My version
VB Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Private Const EM_SETSEL = &HB1
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_LINEINDEX = &HBB
Private Sub DeleteLine(pLineNumber As Long)
Dim chrsToStart As Long, chrsToEnd As Long, lineCount As Long
With RichTextBox1
lineCount = SendMessage(.hwnd, EM_GETLINECOUNT, 0, ByVal 0&)
Select Case True
Case pLineNumber > lineCount - 1
Exit Sub
Case pLineNumber = 0 And lineCount = 1
chrsToStart = 0
chrsToEnd = Len(.Text)
Case pLineNumber = lineCount - 1
chrsToStart = SendMessage(.hwnd, EM_LINEINDEX, pLineNumber, ByVal 0&) - 1
chrsToEnd = Len(.Text) - chrsToStart + 1
Case Else
chrsToStart = SendMessage(.hwnd, EM_LINEINDEX, pLineNumber, ByVal 0&)
chrsToEnd = SendMessage(.hwnd, EM_LINEINDEX, pLineNumber + 1, ByVal 0&) - chrsToStart
End Select
.SetFocus
Call SendMessage(.hwnd, EM_SETSEL, chrsToStart, ByVal chrsToEnd)
LockWindowUpdate .hwnd
.SelStart = chrsToStart
.SelLength = chrsToEnd
.SelText = vbNullString
LockWindowUpdate False
End With
End Sub
Private Sub Command1_Click()
DeleteLine 2 'Deletes line 2 (its the third line, because first line is line 0)
End Sub
-
Jan 6th, 2007, 03:03 AM
#4
Re: Delete Line
Dear Martin,
Will this support a datasize of 4MB.In the meanwhile I am trying JCIS code
Please mark you thread resolved using the Thread Tools as shown
-
Jan 6th, 2007, 09:50 AM
#5
Re: Delete Line
 Originally Posted by danasegarane
Dear Martin,
Will this support a datasize of 4MB.In the meanwhile I am trying JCIS code 
Sorry but I have no idea.
-
Aug 31st, 2008, 10:13 PM
#6
Junior Member
Re: Delete Line
Great stuff guys. The only problem now is that it changes all the color.
now what could be a good work around for that one?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|