Professional Documents
Culture Documents
August 7, 2014
Aim:
~~~~
12PA01
Page 47
August 7, 2014
CODING:
~~~~~~~
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog objOFD = new OpenFileDialog();
objOFD.Filter = "ALL File|*.*|Text Files|*.txt";
objOFD.FilterIndex = 1;
if (objOFD.ShowDialog() == DialogResult.OK)
{
string flname;
flname = objOFD.FileName;
FileStream objFS = new FileStream(flname, FileMode.OpenOrCreate,
FileAccess.ReadWrite);
StreamReader objSR = new StreamReader(objFS);
objSR.BaseStream.Seek(0, SeekOrigin.Begin);
data.Text = objSR.ReadLine();
while (objSR.Peek() > -1)
12PA01
Page 48
August 7, 2014
{
data.Text = data.Text + "\r\n" + objSR.ReadLine();
}
objSR.Close();
}
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog objSFD;
objSFD = new SaveFileDialog();
objSFD.Filter = "All File|*.*|Text files|*.txt";
objSFD.FilterIndex = 1;
if (objSFD.ShowDialog() == DialogResult.OK)
{
data.SaveFile(objSFD.FileName, RichTextBoxStreamType.PlainText);
MessageBox.Show("File Saved");
}
}
private void fontToolStripMenuItem_Click(object sender, EventArgs e)
{
FontDialog objFD = new FontDialog();
if (objFD.ShowDialog() == DialogResult.OK)
{
data.Font = objFD.Font;
}
}
private void colorToolStripMenuItem_Click(object sender, EventArgs e)
{
ColorDialog objCD = new ColorDialog();
if (objCD.ShowDialog() == DialogResult.OK)
{
data.ForeColor = objCD.Color;
}
}
12PA01
Page 49
August 7, 2014
12PA01
Page 50
August 7, 2014
Output:
~~~~~~
12PA01
Page 51
August 7, 2014
Result:
~~~~~
12PA01
Page 52
August 7, 2014
12PA01
Page 53