Insert RTF text before another rtf text RRS feed

  • Question


    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.

    Thursday, September 27, 2007 8:43 AM


  • 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




    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)




    Thursday, September 27, 2007 11:04 AM