
Rich Text Box: Can I remove text and keep multicolored text
On Wed, 18 Sep 2002 17:38:08 -0400, "Chase Sebor"
Quote:
>Thanks to Frank A., my Rich Text Box now has interspersed Blue and Black
>text,
>displaying the serial port recv'd(Blue) and sent(text) data.
>How can I erase some of the oldest text and still maintain the assigned
>colors?
>Using "Replace" or "Mid" both create a new string to assign to the Rich Text
>Box, and
>that string has one color, and so erasing oldest data resets all text in the
>box to that one color.
I'm not sure if there is a quicker way twen this.
Option Explicit
Private Const EM_REPLACESEL = &HC2
Private Const EM_LINEINDEX = &HBB
Private Const EM_GETLINECOUNT = &HBA
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 Sub CutRTBLines(lns As Long)
Dim l As Long
Dim rep As String
rep = ""
l = SendMessage(RTB.hwnd, EM_GETLINECOUNT, 0&, ByVal 0&)
If l > lns Then ' there are more than lns lines
RTB.SelStart = 0
l = SendMessage(RTB.hwnd, EM_LINEINDEX, lns, ByVal 0&)
If l = -1 Then Exit Sub
RTB.SelLength = l
Call SendMessage(RTB.hwnd, EM_REPLACESEL, 0&, ByVal rep)
End If
' otherwise there was no need to cut.
' you may want to add an "else" condition rtb.Text = "" to cut
' all lines in that case.
End Sub
--
Regards, Frank