StreamReader fileRead = new StreamReader(myFilePath); string line = fileRead.ReadLine(); string LookFor = textBox3.Text; string bloc; while (line != null) { if (line.Contains(LookFor)) { bloc = line + "\r\n"; line = fileRead.ReadLine(); do { bloc = bloc + line + "\r\n"; line = fileRead.ReadLine(); } while ((line != null) && !((line.EndsWith("Something")) ||(line.EndsWith("Somethingelse")))); if ((line != null) && ((line.EndsWith("Something")) || (line.EndsWith("Somethingelse")))) { bloc = bloc + line + "\r\n" ; listBox1.Items.Add(bloc); } } line = fileRead.ReadLine(); } } private void listBox1_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); e.DrawFocusRectangle(); e.Graphics.DrawString( (string)listBox1.Items[e.Index], e.Font, new SolidBrush(e.ForeColor), e.Bounds); } private void listBox1_MeasureItem(object sender, MeasureItemEventArgs e) { e.ItemHeight = 13 * GetLinesNumber((string)listBox1.Items[e.Index]); } private int GetLinesNumber(string text) { int count = 1; int pos = 0; while ((pos = text.IndexOf("\r\n", pos)) != -1) { count++; pos += 2; } return count; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)