|
|
Title | Combine the contents of two RichTextBoxes, preserving their formatting |
Description | This 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. |
Keywords | RTF, rich text, rich text box, RichTextBox, combine, join |
Categories | Controls |
|
|
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
|
|
|
|
|
|