Rich Text box masks Line Feed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?SnVzdGluIFJvYmVydHM=?=

    Rich Text box masks Line Feed

    Hi

    I have noticed that the RTB control hides all Linefeed characters in it's
    text properties. Unfortunately these LF characters are masked in the Length
    properties also.

    I need the LF characters to be returned in the RTB.Text / RTB.SelectedTex t
    and the LF characters to be included correctly in the RTB.TextLength /
    RTB.SelectedLen gth properties. Does anyone know how I can achieve this, or
    must I abandon the notion of using the standard MS RTB control.

    Much help appreciated since I have completely floundered without these
    correct text properties.

    Regards
    Justin.


  • =?Utf-8?B?QU1lcmNlcg==?=

    #2
    RE: Rich Text box masks Line Feed

    I need all the CR characters to be included as part of in my Text,
    SelectionStart, SelectionLength , SelectedText, etc. properties.
    I think that rtb's always discard CR. Maybe someone else knows a way to
    retain them - I don't know of a way. vbNewLine on my pc is CRLF, yet all CRs
    go away in rtbs.

    So... howcome do you need to retain all the CRs? It would seem to me that
    you could do all your internal stuff with LF as the line separator, and in
    those (presumably few) cases where CR is absolutely necessary, you could
    replace LF with CR or CRLF. I use rtb's all the time, and that is the way I
    do it. I need to put back CRs in a few situations, eg, notepad wants CRLF,
    so to launch it with contents from an rtb, I replace LF with CRLF like:
    Dim s as String = Replace(rtb.Tex t, vbLf, vbCrLf)

    Comment

    • =?Utf-8?B?SnVzdGluIFJvYmVydHM=?=

      #3
      RE: Rich Text box masks Line Feed

      Thank you for your response.

      Unfortunately I need to interface with another third party application that
      specifies exactly what to do with what text. The interaction is dynamic and
      frequent. The third party application bases all it's text calculations with
      the standard Windows newline character (CRLF). (E.g. Characters at pos
      x,length y = bold). I can't keep copying everything to a string because I
      need the user input too, and have to send that back to the third party app.

      Well, if CR's are not retained in RTB's, does anyone know how I can
      calculate which logical 'line' a specified character position is in? (Not the
      'physical' UI line, but the actual line in the string array)?

      Regards
      Justin
      So... howcome do you need to retain all the CRs? It would seem to me that
      you could do all your internal stuff with LF as the line separator, and in
      those (presumably few) cases where CR is absolutely necessary, you could
      replace LF with CR or CRLF. I use rtb's all the time, and that is the way I
      do it. I need to put back CRs in a few situations, eg, notepad wants CRLF,
      so to launch it with contents from an rtb, I replace LF with CRLF like:
      Dim s as String = Replace(rtb.Tex t, vbLf, vbCrLf)
      >

      Comment

      • =?Utf-8?B?QU1lcmNlcg==?=

        #4
        RE: Rich Text box masks Line Feed

        Well, if CR's are not retained in RTB's, does anyone know how I can
        calculate which logical 'line' a specified character position is in? (Not the
        'physical' UI line, but the actual line in the string array)?
        Have a look at rtb.GetLineFrom CharIndex().
        Line and character numbers are zero based, so if rtb is:

        abc
        def

        with an LF after c (total length 7 chars), then char indices 0..3 are in
        line 0 (a,b,c,LF), and char indices 4..6 are in line 1 (d,e,f).

        Comment

        • =?Utf-8?B?SnVzdGluIFJvYmVydHM=?=

          #5
          RE: Rich Text box masks Line Feed


          I tried that, unfortunately GetLineFromChar Index() returns the UI line, not
          the string array line. So, as the text wraps down the page, the
          GetLineFromChar Index() increments even though there has been no CR.

          I can calculate this using the Lines().Length property, but surely MS must
          have provided a faster and better way to know which line a character is in!

          "AMercer" wrote:
          Well, if CR's are not retained in RTB's, does anyone know how I can
          calculate which logical 'line' a specified character position is in? (Not the
          'physical' UI line, but the actual line in the string array)?
          >
          Have a look at rtb.GetLineFrom CharIndex().
          Line and character numbers are zero based, so if rtb is:
          >
          abc
          def
          >
          with an LF after c (total length 7 chars), then char indices 0..3 are in
          line 0 (a,b,c,LF), and char indices 4..6 are in line 1 (d,e,f).
          >

          Comment

          • =?Utf-8?B?SnVzdGluIFJvYmVydHM=?=

            #6
            RE: Rich Text box masks Line Feed

            Thanks for your input on this one. It's a bit of a frustrating issue, so I
            appreciate the answers and suggestions.

            Regards
            Justin
            >
            This is getting ugly, but you could have two rtbs, one with word wrap and
            one without. Show the one with wordwrap, calculate from the one without word
            wrap, and keep them in sync.
            >
            Alternatively, there is the windows api. Sorry, no warranties for what
            follows.
            >
            Private Declare Function SendMessage Lib "user32" Alias "SendMessag eA" ( _
            ByVal hWnd As IntPtr, _
            ByVal wMsg As Integer, _
            ByVal wParam As Integer, _
            ByVal lParam As Integer) _
            As Integer
            >
            Const WM_USER As Integer = &H400
            Const EM_EXLINEFROMCH AR As Integer = WM_USER + 54
            dim l,c as integer ' zero based line number and character number
            c = some zero based character index
            l = SendMessage(Ric hTextBox1.Handl e, EM_EXLINEFROMCH AR, 0, c)
            >

            Comment

            Working...