Rich text box in WPF


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Rich text box in WPF

  1. #1
    Join Date
    Mar 2008
    Location
    BELGIUM - East Flanders
    Posts
    174

    Rich text box in WPF

    Hey,

    I want to read every line out of a WPF richtextbox. I have the following code, but don't know how to proceed:
    Code:
                    string rtbContents = new TextRange(rtbPaths.Document.ContentStart, rtbPaths.Document.ContentEnd).Text;
                    foreach (string line in rtbContents.Split(/* new line */))
                    {
                        // Do something with every line that is not empty after trim
                    }
    How do I split on a return? (In vb winforms you have control keys, but I can't find it in a c# wpf app.)
    How do I trim the lines (and also remove the \r and other things)?

    Cheers
    BN

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Try this:
    Code:
    string rtbContents = new TextRange(rtbPaths.Document.ContentStart, 
        rtbPaths.Document.ContentEnd).Text;
    foreach (string line in rtbContents.Split('\n'))
    {
        if (line.Trim(' ', '\r').Length != 0)
        {
            // Do something with every line that is not empty after trim
        }
    }
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Mar 2008
    Location
    BELGIUM - East Flanders
    Posts
    174
    Ok, thnx a lot! Got it working. This is how I implemented it:

    Code:
                    string rtbContents = new TextRange(rtbPaths.Document.ContentStart, rtbPaths.Document.ContentEnd).Text;
                    foreach (string line in rtbContents.Split('\n'))
                    {
                        String trimmedLine = line.Trim(' ', '\r');
                        if (trimmedLine.Length > 0)
                        {
                            downloader.Files.Add(new FileDownloader.FileInfo(trimmedLine));
                        }
                    }
    I'm curious, is there a way in WPF to have a simple multi line text box without layout ect? I've messed around with textbox and textarea a little but didn't manage to achieve this.

    Cheers
    BN

Similar Threads

  1. vbCrlf works in text box 1 but not text box 2
    By wisgro in forum VB Classic
    Replies: 7
    Last Post: 09-14-2008, 07:06 AM
  2. Rich text box word wrap!
    By GermanD in forum VB Classic
    Replies: 10
    Last Post: 05-25-2005, 01:44 PM
  3. Viewable lines in a rich text box?
    By Sean Woods in forum VB Classic
    Replies: 0
    Last Post: 02-04-2002, 07:31 PM
  4. Rich Text Control BackColor BUG?
    By Mike Sharp in forum VB Classic
    Replies: 0
    Last Post: 07-26-2001, 06:10 AM
  5. Hiding the text in Rich Text Box
    By Javaid Ahmad in forum VB Classic
    Replies: 2
    Last Post: 04-18-2000, 05:44 AM

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