ARTICLE

TextPad Application in C#

Posted by Prashanth Chindam Articles | C# Language September 27, 2010
In this article you will learn how to use TextPad Application in C#.
Reader Level:
Download Files:
 

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();
        }
    }
}

Login to add your contents and source code to this article
post comment
     
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts