RichTextBox Copy and Paste from one RichTextBox to another.

S

Sam

I'm working on a MailMerge. I have a few simple (I hope) questions to
have my merge to work the way I want.

I have a RichTextBox that has the text in it, with strings like
<<NAME>> that I will need to replace for each row. This is what I
have so far:

'rtbBox is the RichTextBox on the form.
'rtbPrint is the RichTextBox that will be used for printing
'Save the data to a temp RichTextBox, since I need to see <<NAME>>
'for each row.

Dim row As DataRow
Dim rtbTemp As New MyRichTextBox
For Each row In g_dtTable.Rows
rtbTemp.Rtf = rtbBox.Rtf

rtbTemp.Rtf = rtbTemp.Rtf.Replace("<<NAME>>", _
row.Item("Name"))

rtbTemp.Rtf = rtbTemp.Rtf.Replace("<<AGE>>", _
row.Item("Age"))

'I need here to tack on the formated text from
'rtbTemp to rtbPrint
'and insert a pagebreak.

'I've tried rtbPrint.Text &= rtbTemp.Text, but that
'doesn't keep the formatting

'I've tried rtbPrint.Rtf &= rtbTemp.Rtf, but that doesn't
'seem to do anything.
Next
PrintDocument1.Print()


OK. Here are my questions
1. How do you copy text (including it's formatting) and append it to
the END of a DIFFERENT RichTextBox.

2. How do you append a page return to the END of a RichTextBox

Thanks for any help...
 
R

Robert Jacobson

For the first question:

1. In the RichTextBox that you want to modify, change the .SelectionStart
property to the last character in the box, and change the .SelectionLength
to 0. This positions the caret at the end of the text.

2. Get the .rtf property of the box you're copying from, and assign it to
the .SelectedRtf property. E.g.,

RichTextBoxA.SelectedRtf = RichTextBoxB.Rtf.

For the second question:

1. Same as first.

2. RichTextBoxA.SelectedText = (a carriage return/linefeed)


[snip]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top