1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;
namespace Recherche {
public partial class Form1 : Form {
List<String> listedFile = new List<string>();
int lastLine = 0;
public Form1() {
InitializeComponent();
}
private void bt_file_Click(object sender, EventArgs e) {
Stream myStream = null;
listedFile.Clear();
lastLine = 0;
if ( opfile.ShowDialog() == DialogResult.OK ) {
try {
if ( ( myStream = opfile.OpenFile() ) != null ) {
using ( myStream ) {
tb_file.Text = opfile.FileName;
StreamReader sReader = new StreamReader(tb_file.Text);
string line;
while ( ( line = sReader.ReadLine() ) != null ) {
listedFile.Add(line);
}
sReader.Close();
}
}
}
catch ( Exception ex ) {
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
}
private void bt_search_Click(object sender, EventArgs e) {
searchNext();
}
private void bt_next_Click(object sender, EventArgs e) {
searchNext();
}
public void searchNext() {
if ( tb_word.Text != "" ) {
for ( int i = lastLine; i < listedFile.Count; i++ ) {
if ( listedFile[i].ToLower().Contains(tb_word.Text.ToLower()) ) {
tb_find.Text = listedFile[i];
lastLine++;
break;
}
lastLine++;
}
}
}
}
} |