Insert RTF text before another rtf text

Hello everybody,

i have problem with rtf, i write some text in rich text box and before print a need add some rich text formated text before the writed text. This text generate program but i dont no how can i add without lose formating. Thank for help.

[266 byte] By [apofis] at [2008-1-10]
# 1

Hi Apofis

The following code add text (and then formats it) at the end of a rtf document:

'-- rtfText is my RichTextBox

'-->>

dim TheName as string

dim cCompanyName as string

cCompanyName = "Another Company Name"

'--

TheName = My.Application.Info.ProductName & " : " & cCompanyName

rtfText.AppendText(vbCrLf & vbCrLf & vbCrLf & TheName) '<<< over here i append it

'-- from here i format it -->>

rtfText.Find(TheName, RichTextBoxFinds.MatchCase)

rtfText.SelectionFont = New Font("Papyrus", 14)

rtfText.SelectionBackColor = Color.LightGray

rtfText.SelectionAlignment = HorizontalAlignment.Center

'--<<

I also use the following method to replace "tags" with real values in a rtf document:

'-- rtfHold is my RichTextBox

Const ClientTag = "<ClientName>"

dim aStr as string

'--

'-- somewhere i give aStr a value let's say aStr = "Slartibartfast"

'-- the following will replace ALL occurences of <ClientName> to Slartibartfast

'--

Do While rtfHold.Rtf.Contains(ClientTag)

rtfHold.Find(ClientTag, RichTextBoxFinds.MatchCase) '<<- here it 'selects' it

rtfHold.SelectedText = aStr '<< here is the replacement

Loop

'--<<

so maybe you can put a character right in the beginning of the text let's say "~" and then replace it with whatever before you print. (and also formats it)

Louie

LouieG at 2007-10-3 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...