-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotepad.cs
More file actions
94 lines (78 loc) · 2.71 KB
/
Notepad.cs
File metadata and controls
94 lines (78 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.IO;
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 Project3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
// set the title to untitled and clear the text contained in the text box
this.Text = "Untitled";
richTextBox1.Clear();
// release the font from the previous file
richTextBox1.Font.Dispose();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
// title for the open file
openFileDialog1.Title = "Open";
openFileDialog1.Filter = "Text Files (.txt)|*txt|All Files (*.*)|*.*";
// open file
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
StreamReader reader = new StreamReader(File.OpenRead(openFileDialog1.FileName));
// Read user information into the rich text box
richTextBox1.Text = reader.ReadToEnd();
// close streamreader
reader.Dispose();
}
this.Text = openFileDialog1.FileName;
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
// title for the save file
saveFileDialog1.Title = "Save As";
saveFileDialog1.Filter = "Text File (*txt)|*txt| All Files (*.*)|*.*";
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
StreamWriter writer = new StreamWriter(File.Create(saveFileDialog1.FileName));
// save the text contained within the rich text box...
writer.Write(richTextBox1.Text);
// close streamwriter
writer.Dispose();
}
this.Text = saveFileDialog1.FileName;
}
private void wordWrapToolStripMenuItem_Click(object sender, EventArgs e)
{
// set the word wrap to true if it is false
if (!richTextBox1.WordWrap)
{
richTextBox1.WordWrap = true;
}
else
{
richTextBox1.WordWrap = false;
}
}
private void fontToolStripMenuItem_Click(object sender, EventArgs e)
{
if(fontDialog1.ShowDialog() == DialogResult.OK)
{
richTextBox1.Font = fontDialog1.Font;
}
}
}
}