Solved

Parsing a RichText Box like a file?

Posted on 2003-10-24
4
205 Views
Last Modified: 2010-04-16
I am trying to parse email. I have created a richtext box that allows me to drag and drop an email file over it and the email appears in the RichText Box. I want to be able to step through that RichText Box line by line and parse it. Can I use similar commands for stepping through a file to step through the RichText Box? Here is the code that I used to drag and drop the email file into the RichText Box.

private void Form1_Load(object sender, System.EventArgs e)
{          
this.richTextBox1.DragEnter += new System.Windows.Forms.DragEventHandler(this.richTextBox1_DragEnter);  
this.richTextBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.richTextBox1_DragEnter);  
this.richTextBox1.AllowDrop = true;
}

private void richTextBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)  
{  
if (((DragEventArgs)e).Data.GetDataPresent(DataFormats.Text))  
     ((DragEventArgs)e).Effect = DragDropEffects.Copy;
 
else  
     ((DragEventArgs)e).Effect = DragDropEffects.None;  
}
 
private void richTextBox1_DragDrop(object sender, DragEventArgs e)  
{  
richTextBox1.LoadFile((String)e.Data.GetData("Text"), System.Windows.Forms.RichTextBoxStreamType.RichText);  
}

Thanks!
0
Comment
Question by:kingjamez
4 Comments
 
LVL 2

Accepted Solution

by:
smitty22 earned 125 total points
ID: 9615618
You can use RichTextBox's Lines property to get a string array of the lines currently in the text box.
0
 
LVL 6

Assisted Solution

by:zrh
zrh earned 125 total points
ID: 9618785
You can do something like:

StringReader sr = new StringReader(richTextBox1.Text);

StringReader is a descendant of System.IO.TextReader, so that might be what you want.

However, in your richTextBox1_DragDrop event instead of using the LoadFile method, you could open the file yourself using a StreamReader, and parse while writing it to the RichTextBox.
That might give you better performance for larger files, so that you don't have to *essentially* read them twice.

Hope that helps,
ZRH
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now