Open Visual Studio and create a new project.
Give a design to a form like this :-
private void button1_Click(object sender, EventArgs e)
{
if (File.Exists(textBox1.Text) == true)
{
StreamReader sr = new StreamReader(textBox1.Text);
richTextBox1.Text = sr.ReadToEnd();
sr.Close();
}
else
{
MessageBox.Show("This file is not exist");
}
}
private void button2_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
}
Give a design to a form like this :-
Now in the Code file add namespace :-
Using System.IO;Double click on Open button :-
private void button1_Click(object sender, EventArgs e)
{
if (File.Exists(textBox1.Text) == true)
{
StreamReader sr = new StreamReader(textBox1.Text);
richTextBox1.Text = sr.ReadToEnd();
sr.Close();
}
else
{
MessageBox.Show("This file is not exist");
}
}
Double click on Clear button :-
private void button2_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
}
No comments:
Post a Comment