Rich Text Box: Can I remove text and keep multicolored text 
Author Message
 Rich Text Box: Can I remove text and keep multicolored text

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.


Mon, 07 Mar 2005 05:38:08 GMT  
 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



Mon, 07 Mar 2005 06:42:33 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Truncating rich text box text & keeping formatting

2. Colour Text Box/Class Wrapper for Rich Text Box

3. Newbie question: Rich Text Box vs. Text Box

4. help: formatting rich text box/text box

5. Rich Text Box vs. Text Box Scrolling

6. Rich Text Box or text box control

7. Looking for APIs for text box and Rich text box

8. Formatted text from rich text box to Word

9. Keeping focus on button while entering text in text box

10. Put text inside a circle in a Rich Text Box

11. Some [hopefully] easy questions - text and rich text boxes

12. Rich Text Box: Coloring portions of the text

 

 
Powered by phpBB® Forum Software