Hi I was wondering if someone could help me. I would like to able to be to have my program give the user the ability to only read a certain block of code from a text document. However I would like it to be placed behind a button so it can be turned on and off. I have experimented wih different ways of doing this but nothing has made the slightest bit of difference.
This is how my code stands at the moment.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace filestream
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string Read(string file)
{
StreamReader reader = new StreamReader(file);
string data = reader.ReadToEnd();
reader.Close();
return data;
}
private void btn1_Click(object sender, EventArgs e)
{
textBox1.Text = "";
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
string data = Read(openFileDialog1.FileName);
textBox1.Text = data;
}
else
{
//do nothing
}
}
private void button1_Click(object sender, EventArgs e)
{
{
TextReader tr = new StreamReader("C:\\Users\\Bob\\Documents\\Uni Work year 3\\Software\\ASDB2010\\09072501.hrm");
int NumberOfLines = 15;
string[] ListLines = new string[NumberOfLines];
for (int i = 1; i < NumberOfLines; i++)
{
ListLines[i] = tr.ReadLine();
}
Console.WriteLine(ListLines[5]);
Console.WriteLine(ListLines[1]);
}
}
}
}
Im quite new at this so any help would be greatly appreciated.