Advanced Notepad Code in C#.net

Advanced Notepad Code in C#.net

I am going to share with you my Advance Notepad code. If you are looking for to make advance notepad code, the following code will be beneficial for you.

Students can make Notepad application using c# and I will share the code which i have used to make notepad application in my semesters.

Advanced Notepad Code in C#.net

//Language  is C#.Net

//Advanced Notepad Code

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.IO;

 

namespace NotepadOnCSharp{

public partial class Form1 : Form{

public Form1(){

InitializeComponent();}

PageSetupDialog psd = new PageSetupDialog();

PrintDialog prd = new PrintDialog();

FontDialog fd = new FontDialog();

ColorDialog cd = new ColorDialog();

private void saveAsToolStripMenuItem_Click(object sender, EventArgs e){

SaveFileDialog sfd = new SaveFileDialog();

sfd.Filter = “Text Document|*.txt|All Files | *.*”;

if (sfd.ShowDialog() == DialogResult.OK){

FileStream fs = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);

StreamWriter sr = new StreamWriter(fs);

sr.Write(richTextBox1);

sr.Close();

fs.Close();}}

private void newToolStripMenuItem_Click(object sender, EventArgs e){

if (richTextBox1.Text == “”){

Show();}

else{

//richTextBox1.Text = “”;

DialogResult res = new DialogResult();

res =  MessageBox.Show(“Save changes…?”,”New File”,MessageBoxButtons.YesNoCancel);

if (res == DialogResult.Yes){

SaveFileDialog sfd = new SaveFileDialog();

sfd.Filter = “Text Document | *.txt | All Files | *.*”;

if (sfd.ShowDialog() == DialogResult.OK){

FileStream fs = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);

BinaryWriter bw=new BinaryWriter(fs);

bw.Write(richTextBox1.Text);

bw.Close();

fs.Close();}}

else if(res == DialogResult.No){

Show();

richTextBox1.Clear();}

else if(res == DialogResult.Cancel){

Show();}}}

private void openToolStripMenuItem_Click(object sender, EventArgs e){

if (richTextBox1.Text == “”){

OpenFileDialog ofd = new OpenFileDialog();

ofd.Filter = “Text Document|*.txt|All Files|*.*”;

if (ofd.ShowDialog() == DialogResult.OK){

FileStream fs = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read);

StreamReader sr = new StreamReader(fs);

sr.BaseStream.Seek(0, SeekOrigin.Begin);

//BinaryReader br=new BinaryReader(fs);

//br.BaseStream.Seek(0, SeekOrigin.Begin);

//long length = fs.Length;

richTextBox1.Text = sr.ReadToEnd();

//richTextBox1.Text = br.ReadString();

sr.Close();

// br.Close();

fs.Close();}}

else{

//richTextBox1.Text = “”;

DialogResult res = new DialogResult();

res = MessageBox.Show(“Save changes…?”, “New File”, MessageBoxButtons.YesNoCancel);

if (res == DialogResult.Yes){

SaveFileDialog sfd = new SaveFileDialog();

sfd.Filter = “Text Document | *.txt | All Files | *.*”;

if (sfd.ShowDialog() == DialogResult.OK){

FileStream fs = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);

BinaryWriter bw = new BinaryWriter(fs);

bw.Write(richTextBox1.Text);

bw.Close();

fs.Close();

//open dialog

OpenFileDialog ofd = new OpenFileDialog();

ofd.Filter = “Text Document|*.txt|All Files|*.*”;

if (ofd.ShowDialog() == DialogResult.OK){

FileStream fs1 = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read);

StreamReader sr = new StreamReader(fs1);

sr.BaseStream.Seek(0, SeekOrigin.Begin);

//BinaryReader br=new BinaryReader(fs);

//br.BaseStream.Seek(0, SeekOrigin.Begin);

//long length = fs.Length;

richTextBox1.Text = sr.ReadToEnd();

//richTextBox1.Text = br.ReadString();

sr.Close();

// br.Close();

fs1.Close();}

else if (res == DialogResult.No){

Show();

richTextBox1.Clear();}

else if (res == DialogResult.Cancel){

this.Show();}}}

else if (res == DialogResult.No){

OpenFileDialog ofd1 = new OpenFileDialog();

ofd1.Filter = “Text Document|*.txt|All Files|*.*”;

if (ofd1.ShowDialog() == DialogResult.OK){

FileStream fs2 = new FileStream(ofd1.FileName, FileMode.Open, FileAccess.Read);

StreamReader sr = new StreamReader(fs2);

sr.BaseStream.Seek(0, SeekOrigin.Begin);

//BinaryReader br=new BinaryReader(fs);

//br.BaseStream.Seek(0, SeekOrigin.Begin);

//long length = fs.Length;

richTextBox1.Text = sr.ReadToEnd();

//richTextBox1.Text = br.ReadString();

sr.Close();

// br.Close();

fs2.Close();}}}}

private void saveToolStripMenuItem_Click(object sender, EventArgs e){

SaveFileDialog sfd = new SaveFileDialog();

sfd.Filter = “Text Document|*.txt|All Files | *.*”;

if (sfd.ShowDialog() == DialogResult.OK){

FileStream fs = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);

StreamWriter sr=new StreamWriter(fs);

sr.Write(richTextBox1);

sr.Close();

fs.Close();}}

private void Form1_Load(object sender, EventArgs e){}

private void Form1_FormClosed(object sender, FormClosedEventArgs e){

if (richTextBox1.Text == “”){

Show();}

else{

//richTextBox1.Text = “”;

DialogResult res = new DialogResult();

res = MessageBox.Show(“Save changes…?”, “New File”, MessageBoxButtons.YesNoCancel);

if (res == DialogResult.Yes){

SaveFileDialog sfd = new SaveFileDialog();

sfd.Filter = “Text Document | *.txt | All Files | *.*”;

if (sfd.ShowDialog() == DialogResult.OK){

FileStream fs = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);

BinaryWriter bw = new BinaryWriter(fs);

bw.Write(richTextBox1.Text);

bw.Close();

fs.Close();}}

else if (res == DialogResult.No){

Show();

richTextBox1.Clear();}

else if (res == DialogResult.Cancel){

this.Show();}}}

private void Form1_FormClosing(object sender, FormClosingEventArgs e){}

private void richTextBox1_TextChanged(object sender, EventArgs e){}

private void Form1_Leave(object sender, EventArgs e){}

private void pageSetupToolStripMenuItem_Click(object sender, EventArgs e){

//psd.PageSettings pgs= new System.Drawing.Printing.PageSettings();

//psd.ShowDialog();

//psd.ShowDialog();}

private void printToolStripMenuItem_Click(object sender, EventArgs e){

prd.ShowDialog();}

private void exitToolStripMenuItem_Click(object sender, EventArgs e){

if (richTextBox1.Text == “”){

this.Close();}

else{

//richTextBox1.Text = “”;

DialogResult res = new DialogResult();

res = MessageBox.Show(“Save changes…?”, “New File”, MessageBoxButtons.YesNoCancel);

if (res == DialogResult.Yes){

SaveFileDialog sfd = new SaveFileDialog();

sfd.Filter = “Text Document | *.txt | All Files | *.*”;

if (sfd.ShowDialog() == DialogResult.OK){

FileStream fs = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);

BinaryWriter bw = new BinaryWriter(fs);

bw.Write(richTextBox1.Text);

bw.Close();

fs.Close();}}

else if (res == DialogResult.No){

this.Close();}

else if (res == DialogResult.Cancel){

Show();}}}

private void undoToolStripMenuItem_Click(object sender, EventArgs e){

richTextBox1.Undo();}

private void cutToolStripMenuItem_Click(object sender, EventArgs e){

richTextBox1.Cut();}

private void copyToolStripMenuItem_Click(object sender, EventArgs e){

richTextBox1.Copy();}

private void pasteToolStripMenuItem_Click(object sender, EventArgs e){

richTextBox1.Paste();}

private void deleteToolStripMenuItem_Click(object sender, EventArgs e){

richTextBox1.SelectedText = “”;}

private void goToToolStripMenuItem_Click(object sender, EventArgs e){}

private void selectAllToolStripMenuItem_Click(object sender, EventArgs e){

richTextBox1.SelectAll();}

private void dateTimeToolStripMenuItem_Click(object sender, EventArgs e){

DateTime dt = new DateTime();

string d = Convert.ToString(dt.Date);

richTextBox1.Text = d;}

private void fontToolStripMenuItem_Click(object sender, EventArgs e){

fd.ShowDialog();

richTextBox1.Font = fd.Font;}

private void colorToolStripMenuItem_Click(object sender, EventArgs e){

//     cd.ShowDialog()

//TextBox1.ForeColor = cd.Color

cd.ShowDialog();

richTextBox1.ForeColor = cd.Color;}

private void wordwrapToolStripMenuItem_Click(object sender, EventArgs e){

//    If MenuItem29.Checked = True Then

//    MenuItem29.Checked = False

//    MenuItem31.Enabled = True

//    TextBox1.WordWrap = False

//ElseIf MenuItem29.Checked = False Then

//    MenuItem29.Checked = True

//    TextBox1.WordWrap = True

//    MenuItem31.Checked = False

//    MenuItem31.Enabled = False

//End If

if (wordwrapToolStripMenuItem.Checked == true){

wordwrapToolStripMenuItem.Checked = false;

richTextBox1.WordWrap = false;}

else if (wordwrapToolStripMenuItem.Checked == false){

wordwrapToolStripMenuItem.Checked = true;

richTextBox1.WordWrap = true;}}

private void statusBarToolStripMenuItem_Click(object sender, EventArgs e){

//statusBarToolStripMenuItem.Visible = true;

//      If MenuItem31.Checked = True Then

//    MenuItem31.Checked = False

//    StatusBar1.Visible = False

//ElseIf MenuItem31.Checked = False Then

//    MenuItem31.Checked = True

//    StatusBar1.Visible = True

//End If

if (statusBarToolStripMenuItem.Checked == true){

statusBarToolStripMenuItem.Checked = false;

statusStrip1.Visible = false;}

else if (statusBarToolStripMenuItem.Checked == false){

statusBarToolStripMenuItem.Checked = true;

statusStrip1.Visible = true;}}

private void aboutSunbiosToolStripMenuItem_Click(object sender, EventArgs e){}

private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e){}}}

Advanced Notepad

Thanks for your attention, how do you rate this article on Advanced Notepad Code in C#.net

Some useful references:

How to create a Notepad in VS C#

About

Hi, This is R K Gupta, an IT professional and Entrepreneur. I have written many articles yet for my websites gsesoftsolutions.com, Hope you like it. Kindly subscribe our feed for any updates. Add me in Facebook and Google+

Posted in Software Development

Leave a Reply

Your email address will not be published. Required fields are marked *

*