?
Solved

Parsing a RichText Box like a file?

Posted on 2003-10-24
4
Medium Priority
?
213 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 2

Accepted Solution

by:
smitty22 earned 500 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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

764 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