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
|
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "Load Text File";
openFileDialog1.DefaultExt = "txt";
openFileDialog1.Filter = "fichiers textes (*.txt)|*.txt|Tous les fichiers (*.*)|*.*";
openFileDialog1.FilterIndex = 1;
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
richTextBox1.Text = string.Empty;
StreamReader sr = new StreamReader(openFileDialog1.OpenFile(), Encoding.Default);
try
{
string data = sr.ReadLine();
while (data != null)
{
richTextBox1.AppendText(data + "\r\n");
data = sr.ReadLine();
}
}
finally
{
if (sr != null)
sr.Close();
}
} |