Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleCombine the contents of two RichTextBoxes, preserving their formatting
DescriptionThis example shows how to combine the contents of two RichTextBoxes, preserving their formatting in Visual Basic 6. It uses the controls' SelRTF properties to get the text with its formatting.
KeywordsRTF, rich text, rich text box, RichTextBox, combine, join
CategoriesControls
 
Select the text to be combined in the two controls. Use the SelRTF properties to get the text with its formatting codes.
 
Private Sub cmdCopy_Click()
Dim old_pos As Integer
Dim old_len As Integer

    m_IgnoreChanges = True

    ' Copy the first control's text.
    rchOutput.SelStart = 0
    rchOutput.SelLength = Len(rchOutput.Text)
    old_pos = rchInput(0).SelStart
    old_len = rchInput(0).SelLength
    rchInput(0).SelStart = 0
    rchInput(0).SelLength = Len(rchInput(0).Text)
    rchOutput.SelRTF = rchInput(0).SelRTF
    rchInput(0).SelStart = old_pos
    rchInput(0).SelLength = old_len

    ' Add a vbCrLf.
    rchOutput.SelStart = Len(rchOutput.Text)
    rchOutput.SelLength = 0
    rchOutput.SelText = vbCrLf

    ' Add the second control's text.
    rchOutput.SelStart = Len(rchOutput.Text)
    rchOutput.SelLength = 0
    old_pos = rchInput(1).SelStart
    old_len = rchInput(1).SelLength
    rchInput(1).SelStart = 0
    rchInput(1).SelLength = Len(rchInput(1).Text)
    rchOutput.SelRTF = rchInput(1).SelRTF
    rchInput(1).SelStart = old_pos
    rchInput(1).SelLength = old_len

    m_IgnoreChanges = False
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated