Solved

Parsing a RichText Box like a file?

Posted on 2003-10-24
4
211 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 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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