Results 1 to 7 of 7

Thread: Getting Formatted Text from a RichTextBox

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2010
    Posts
    56

    Getting Formatted Text from a RichTextBox

    Hey, everyone! I've decided to come back to working on an old program of mine, and it's been coming along nicely, but there's this one thing that I can't get working.

    I have formatting options (Bold, Underline, Italics, Strikethrough) available on my program, and they all work properly. I'm giving users the ability to export all of their text from a single page on the program to a .rtf file. However, the problem I'm experiencing is that each page has numerous RichTextBoxes on it, so I cannot simply use a RichTextBox1.SaveFile() command or something similar. I want to compile all of the text (including formatting) from all of the RichTextBoxes and put it on a single .rtf file. Currently, I'm getting the text from the RichTextBoxes using the RichTextBox1.Text command; unfortunately, that only gives me plain text without formatting. So, what I'm wondering is: how can I get the formatted text from a RichTextBox? Is there any command?

    Thanks, and any help would be greatly appreciated!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Getting Formatted Text from a RichTextBox

    As you say, the Text property gets just the text and not the markup. When you read the documentation for the RichTextBox class, you'd have noticed that the Rtf property is the one you use to get the markup and text.

    I've never actually tried to combine the contents of multiple RTB controls. I'm not sure if it's as easy as simply concatenating the Rtf properties because each one probably contains its own root node. I've seen mention of classes designed to work with RTF data in code with no UI. I have no experience with any of them or even know where to find them, but if you search around you may be able to find one or more and they may be able to do what you want.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Getting Formatted Text from a RichTextBox

    http://www.bing.com/search?FORM=WLET....net+rtf+class

    The fourth result there looks promising. The code is C# but you can reference a C# library in VB.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Member
    Join Date
    Oct 2010
    Posts
    56

    Re: Getting Formatted Text from a RichTextBox

    Okay, thanks a lot! However, how would I reference this class? I've downloaded it, and it's just a bunch of separate Visual C# source files.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Getting Formatted Text from a RichTextBox

    As with your own source files, you must build the project to create an executable. If you don't want to look at and/or edit the source code then don't download the source code. Download the already-built executable.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Member
    Join Date
    Oct 2010
    Posts
    56

    Re: Getting Formatted Text from a RichTextBox

    Well, I've downloaded it and used it, but it doesn't seem to do what I need.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Getting Formatted Text from a RichTextBox

    That may or may not be true. It may not have a single method that will do what you want in a single line but that doesn't necessarily mean that you can't achieve you aim with some combination of types and members. Then again, it may not be capable of doing what you need. I can't be of any more help than that I'm afraid as I've never used it or anything like it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width