Rich text box word wrap!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 11 of 11

Thread: Rich text box word wrap!

  1. #1
    Join Date
    Apr 2005
    Location
    South Africa
    Posts
    88

    Exclamation Rich text box word wrap!

    Hi there,
    How can I add a word wrap and non word wrap option to a rich text box like Windows Notepad?

    Thanks in advance!
    GermanD
    deonmeyer@gmail.com
    ** <<]db[>> **
    *** G.s.G Crew ***

  2. #2
    Join Date
    Dec 2003
    Posts
    2,750
    Try setting the RightMargin property to a very large number (100000 should be sufficient) to eliminate word wrap, and then back to zero so that word wrap occurs.
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  3. #3
    Join Date
    Apr 2005
    Location
    South Africa
    Posts
    88
    Thanks its working but I have one question though, I opened a txt file to test it and it worked but one of line was long but the margins where still going furthe and then I tried the same with Notepad and the margins stopped right at the end of the long line,
    Do you maybe know how to do that?
    Hope you understand what I'm trying to say!
    GermanD
    deonmeyer@gmail.com
    ** <<]db[>> **
    *** G.s.G Crew ***

  4. #4
    Join Date
    Dec 2003
    Posts
    2,750
    No I'm afraid I don't understand what you are saying. How many lines are there in Notepad and how many lines are there in the RichTextBox after you open the file?
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  5. #5
    Join Date
    Apr 2005
    Location
    South Africa
    Posts
    88
    I uploaded a picture to demonstrate.
    I have set my margins to a certain value that is 100000 and I thing win notepad checks how long is the longest line and then sets the margins to the exact number of charactes in that line.
    I you do not understand or don't know how to do it, thats fine its not that big of a problem!
    Attached Images Attached Images
    GermanD
    deonmeyer@gmail.com
    ** <<]db[>> **
    *** G.s.G Crew ***

  6. #6
    Join Date
    Dec 2003
    Posts
    2,750
    Yeah, I don't know of a way to solve this problem off the top of my head. If I think of anything I'll let you know.
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  7. #7
    Join Date
    Apr 2005
    Location
    South Africa
    Posts
    88
    Thanks alot, I appreciate it!
    GermanD
    deonmeyer@gmail.com
    ** <<]db[>> **
    *** G.s.G Crew ***

  8. #8
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    try setting the right marging to the widest line of the text (use TextWidth function)
    Marco
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

  9. #9
    Join Date
    Apr 2005
    Location
    South Africa
    Posts
    88
    It works, thanks alot!
    Don't know if I used the function correctly but it works, here is the code I added,
    Code:
    rtfNotepad.RightMargin = TextWidth(rtfNotepad.Text)
    GermanD
    deonmeyer@gmail.com
    ** <<]db[>> **
    *** G.s.G Crew ***

  10. #10
    Join Date
    Dec 2003
    Posts
    2,750
    Nice tip! I wouldn't have guessed that it would have worked that way by specifying the complete text.
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  11. #11
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    Quote Originally Posted by pclement
    Nice tip! I wouldn't have guessed that it would have worked that way by specifying the complete text.
    neither did I. Sometimes VB is smarter than we think.

    to GermanD: when the object of a method is not specified, VB call the default object. Your code works because you are in a form module, where there is a default object (Me, like Me.TextWidth). Probably (not tested) will not work in a bas module.
    One more thing: be sure that me.font and the text box font are the same, otherwise TextWidth returns a wrong answer

    Marco
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center