Rtf and variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sam

    #1

    Rtf and variable

    Hi,
    How can I assign the content of a string variable to the Rtf property
    of a richtextbox :

    Dim message As String = txtMessage.Rtf & "[" &
    DirectCast(lstF ields.SelectedI tem, Field).FieldNam e & "]"
    txtMessage.Rtf = "{\rtf1\ans i message}"

    This displays 'message' instead of its content :(

    Thx

  • Oenone

    #2
    Re: Rtf and variable

    Sam wrote:[color=blue]
    > txtMessage.Rtf = "{\rtf1\ans i message}"[/color]

    Do you mean:

    \\\
    txtMessage.Rtf = "{\rtf1\ans i " & message & "}"
    ///

    ?

    --

    (O)enone


    Comment

    • Sam

      #3
      Re: Rtf and variable

      oh ! it was that simple ? thx !
      By any luck, do you know how to append text in a richtextbox ?
      Something like :

      Dim message As String = txtMessage.Rtf & "[" &
      DirectCast(lstF ields.SelectedI tem, Field).FieldNam e & "]"
      txtMessage.Rtf = "{\rtf1\ans i
      {\colortbl;\red 0\green0\blue0; \red255\green0\ blue0;} \cf2" & message &
      "\cf1}"

      That doesn't work :(

      Comment

      • Sam

        #4
        Re: Rtf and variable

        I've found out.... just had to replace txtmessage.rtf & by
        txtmessage.text &

        Comment

        • Sam

          #5
          Re: Rtf and variable

          Now I have another problem :
          txtMessage.Rtf = "{\rtf1\ans i
          {\colortbl;\red 0\green0\blue0; \red0\green200\ blue0;}" & txtMessage.Text
          & "\cf2" & message & "\cf0}"

          In the above, the color of 'message' is green but then the text that
          one types afterward should be black again as I do & "\cf0}". But
          instead the text remains always green. Why ?

          Comment

          • Sam

            #6
            Re: Rtf and variable

            also, the following has no effect at all on my text :
            txtMessage.Sele ctionColor = Color.Red
            txtMessage.Sele ct(iCntr, 2)

            the text is not selected and there's no color change,
            can you help ?

            Comment

            • Sam

              #7
              Re: Rtf and variable

              I've found out what's going on,
              iCntr was based on my message lenght, but that was comprising all the
              Rtf stuff before my actual text. Now iCntr is correct and the text is
              selected properly. However it is not red.... why ?

              Comment

              • Sam

                #8
                Re: Rtf and variable

                I've found out what's going on,
                iCntr was based on my message lenght, but that was comprising all the
                Rtf stuff before my actual text. Now iCntr is correct and the text is
                selected properly. However it is not red.... why ?

                Comment

                Working...