-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
155 lines (138 loc) · 5.14 KB
/
Form1.cs
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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 Notepad
{
public partial class Form1 : Form
{
OpenFileDialog file_open = new OpenFileDialog();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
file_open.Filter = "Rich Text File (*.rtf)|*.rtf|Plain Text File (*.txt)|*.txt";
file_open.FilterIndex = 1;
file_open.Title = "Open RTF or TXT file";
RichTextBoxStreamType stream_type;
stream_type = RichTextBoxStreamType.RichText;
if (DialogResult.OK == file_open.ShowDialog())
{
if (string.IsNullOrEmpty(file_open.FileName))
{
return;
}
if (file_open.FilterIndex == 2)
{
stream_type = RichTextBoxStreamType.PlainText;
}
richTextBox1.LoadFile(file_open.FileName, stream_type);
string s = file_open.FileName.ToString();
int c=s.LastIndexOf('\\');
int x = s.LastIndexOf('.');
int d = x - c;
this.Text = s.Substring(c + 1, d-1);
}
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog save_file = new SaveFileDialog();
string filename = "";
save_file.Filter = "Rich Text File (*.rtf)|*.rtf|Plain Text File (*.txt)|*.txt";
save_file.DefaultExt = "*.rtf";
save_file.FilterIndex = 1;
save_file.Title = "Save the contents";
filename = file_open.FileName;
RichTextBoxStreamType stream_type;
if (filename.Contains(".txt"))
{
stream_type = RichTextBoxStreamType.PlainText;
}
else
{
stream_type = RichTextBoxStreamType.RichText;
}
richTextBox1.SaveFile(filename, stream_type);
}
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog save_file = new SaveFileDialog();
string filename = "";
save_file.Filter = "Rich Text File (*.rtf)|*.rtf|Plain Text File (*.txt)|*.txt";
save_file.DefaultExt = "*.rtf";
save_file.FilterIndex = 1;
save_file.Title = "Save the contents";
DialogResult retval = save_file.ShowDialog();
if (retval == DialogResult.OK)
filename = save_file.FileName;
else
return;
RichTextBoxStreamType stream_type;
if (save_file.FilterIndex == 2)
stream_type = RichTextBoxStreamType.PlainText;
else
stream_type = RichTextBoxStreamType.RichText;
richTextBox1.SaveFile(filename, stream_type);
this.Text = filename.ToString();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void cutToolStripMenuItem_Click(object sender, EventArgs e)
{
if (richTextBox1.TextLength > 0)
richTextBox1.Cut();
}
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
if (richTextBox1.TextLength > 0)
richTextBox1.Copy();
}
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
if (richTextBox1.TextLength > 0)
richTextBox1.Paste();
}
private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
if (richTextBox1.TextLength > 0)
richTextBox1.SelectAll();
}
private void fontToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult result = fontDialog1.ShowDialog();
if (result == DialogResult.OK)
{
Font font = fontDialog1.Font;
this.richTextBox1.Font = font;
}
}
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("Options:\n\nFile Open : Press 'CTRL + O'\nFile Save : Press 'CTRL + S'\nCut : Press 'CTRL + X'\nCopy : Press 'CTRL + C'\nPaste : Press 'CTRL + V'\n");
}
private void lightToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.BackColor = Color.White;
richTextBox1.ForeColor = Color.Black;
panel1.BackColor = Color.White;
}
private void darkToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.BackColor = Color.Black;
richTextBox1.ForeColor = Color.White;
panel1.BackColor = Color.Black;
}
}
}