TextPad Application in C#


TextPad.gif 

using
System;
using
System.Windows.Forms;
using
System.IO;
namespace
prash_textpad
{
    public partial class prash_textpad : Form
    {
        public prash_textpad()
        {
            InitializeComponent();
        }
        private void open_btn_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "text|*.txt|documents|*.doc|AllFiles|*.*";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
                StreamReader sr = new StreamReader(fs);
                string s, str = null;
                s = sr.ReadLine();
                while (s != null)
                {
                    str = str + s + Convert.ToChar(13) + Convert.ToChar(10);
                    s = sr.ReadLine();
                }
                textBox1.Text = str;
                sr.Close();
                fs.Close();
            }
        }
        private void save_btn_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Filter = "text|*.txt|documents|*.doc|AllFiles|*.*";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create, FileAccess.ReadWrite);
                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine(textBox1.Text);
                sw.Close();
                fs.Close();
            }
        }
        private void clear_btn_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
        }
        private void exit_btn_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

Up Next
    Ebook Download
    View all
    Learn
    View all