Announcement

Collapse
No announcement yet.

Multi-line textbox with fixed-width word-wrap and scrollbar

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multi-line textbox with fixed-width word-wrap and scrollbar

    I need a multi-line textbox that accepts no more than 80 fixed-width characters per line. When a line reaches 80 characters, it should word wrap. I am also limited on real-estate and only able to display the left half of the textbox, so I need a horizontal scroll bar so the user can scroll the text into view.

    Any ideas? Thanks in advance.

  • #2
    Try the EM_SETRECT message. Calculate the width of your RECT based in the font (GetTextExtent32()) so that what will fit will be 80 characters.

    OR

    Subclass the control and on each character calculate where you are relative to your 80 character limit; if over, scan backward for an allowed word-break character, and insert a line feed at that point.

    The scrollbar is simply style WS_HSCROLL.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Originally posted by Mark Downs View Post
      I need a multi-line textbox that accepts no more than 80 fixed-width characters per line.

      When a line reaches 80 characters, it should word wrap. I am also limited on real-estate and only able to display the left half of the textbox, so I need a horizontal scroll bar so the user can scroll the text into view.
      The TB will have to be be created with %WS_HSCROLL & Multiline in the style. As for how it displays, that's up to the size of the TB and the font used. The display can be manipulated by the programmer if the TB is subclassed.

      If a single line TB, the character limit per line can be set by sending
      Code:
      Control Send hdlg, %Id, %EM_SETLIMITTEXT, 80, 0
      but that wouldn't work on a Multiline.

      ===============================
      "A man can't be too careful
      in the choice of his enemies."
      Oscar Wilde (1854-1900)
      ===============================
      It's a pretty day. I hope you enjoy it.

      Gösta

      JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
      LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

      Comment


      • #4
        Question, do you send the text string to the control, or does a user input?
        If you send it to the control, and no user will modify it, format the string first.

        If the user inputs on the fly, maybe look into


        EM_SETWORDBREAKPROC Message

        Replaces an edit CONTROL's default Wordwrap function with an application-defined
        Wordwrap function. You can SEND this message TO either an edit CONTROL OR a
        rich edit control.

        EditWordBreakProc
        An application-defined CALLBACK FUNCTION used WITH the EM_SETWORDBREAKPROC message.
        A multiline edit CONTROL OR a rich edit CONTROL calls an EditWordBreakProc FUNCTION
        TO BREAK a LINE OF text.


        FUNCTION EditWordBreakProc(...)
        SELECT CASE wActionCode
        CASE %WB_ISDELIMITER
        CASE %WB_LEFT
        CASE %WB_RIGHT
        END SELECT
        END FUNCTION
        Best regards
        Jules
        www.rpmarchildon.com

        Comment

        Working...
        X