0% found this document useful (0 votes)
56 views3 pages

Notepad Coding

This document contains C# code for a basic notepad application. It includes code for opening, saving, and editing text files. Methods are defined to handle menu item clicks for common editing functions like cut, copy, paste, undo, and changing font/color. Strings are used to track cut/copied text. An undo stack tracks previous actions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views3 pages

Notepad Coding

This document contains C# code for a basic notepad application. It includes code for opening, saving, and editing text files. Methods are defined to handle menu item clicks for common editing functions like cut, copy, paste, undo, and changing font/color. Strings are used to track cut/copied text. An undo stack tracks previous actions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NotepadApplication
{
public partial class Form1 : Form
{

String cutText = "";


String copyText = "";

public Form1()
{
InitializeComponent();
}

Stack<Action> undoAction = new Stack<Action>();

private void editToolStripMenuItem_Click(object sender, EventArgs e)


{

private void savesToolStripMenuItem_Click(object sender, EventArgs e)


{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Text file|*.txt";
sfd.InitialDirectory = "C:/";
sfd.ShowDialog();

if(sfd.FileName != "")
{
System.IO.FileStream fs = (System.IO.FileStream) sfd.OpenFile();
byte[] filetext = Encoding.ASCII.GetBytes(TextArea.Text);
fs.Write(filetext,0,filetext.Length);
fs.Close();
}

private void richTextBox1_TextChanged(object sender, EventArgs e)


{

private void fileToolStripMenuItem1_Click(object sender, EventArgs e)


{

private void quitToolStripMenuItem_Click(object sender, EventArgs e)


{
Application.Exit();
}

private void toolStripTextBox1_Click(object sender, EventArgs e)


{

private void fileToolStripMenuItem2_Click(object sender, EventArgs e)


{
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = "C:/Desktop";
ofd.Filter = "Text File|*txt";
ofd.ShowDialog();

if (ofd.FileName != "")
{
String[] fileLines = System.IO.File.ReadAllLines(ofd.FileName);
TextArea.Text = "";

for (int a = 0; a < fileLines.Length; a++)


{
TextArea.AppendText(fileLines[a]);
TextArea.AppendText("\n");
}

}
}

private void fieToolStripMenuItem_Click(object sender, EventArgs e)


{
Form1 f = new Form1();
f.ShowDialog();
}

private void cutToolStripMenuItem_Click(object sender, EventArgs e)


{
cutText = TextArea.Text;
copyText = "";
TextArea.SelectedText = "";
}

private void copyToolStripMenuItem_Click(object sender, EventArgs e)


{
copyText = TextArea.SelectedText;
cutText = "";
}

private void undoToolStripMenuItem_Click(object sender, EventArgs e)


{
if (undoAction.Count > 0)
{
Action cmd = undoAction.Pop();

}
}
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
if (cutText.Length > 0)
{

TextArea.Text = TextArea.Text.Insert(TextArea.SelectionStart,
cutText);
}
else
{
TextArea.Text = TextArea.Text.Insert(TextArea.SelectionStart,
copyText);
}

private void changeFontToolStripMenuItem_Click(object sender, EventArgs e)


{
if (fontDialog1.ShowDialog() == DialogResult.OK &&
TextArea.SelectedText.Length > 0)
{
TextArea.SelectionFont = fontDialog1.Font;
}

private void changeColorToolStripMenuItem_Click(object sender, EventArgs e)


{
if (colorDialog1.ShowDialog() == DialogResult.OK &&
TextArea.SelectedText.Length > 0)
{
TextArea.SelectionColor = colorDialog1.Color;
}

}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy