-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystem32Notepad.cs
More file actions
119 lines (104 loc) · 4.08 KB
/
System32Notepad.cs
File metadata and controls
119 lines (104 loc) · 4.08 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
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
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace System32Notepad
{
public class Notepad : Form
{
private RichTextBox textArea;
private MenuStrip menu;
private string currentFile = "";
public Notepad()
{
this.Text = "System32 Notepad";
this.Width = 800;
this.Height = 600;
textArea = new RichTextBox
{
Dock = DockStyle.Fill,
Font = new Font("Consolas", 12),
BackColor = Color.Black,
ForeColor = Color.Lime
};
this.Controls.Add(textArea);
menu = new MenuStrip();
this.MainMenuStrip = menu;
this.Controls.Add(menu);
// File menu
var fileMenu = new ToolStripMenuItem("File");
fileMenu.DropDownItems.Add("New", null, (s, e) => { textArea.Clear(); currentFile = ""; });
fileMenu.DropDownItems.Add("Open", null, OpenFile);
fileMenu.DropDownItems.Add("Save", null, SaveFile);
fileMenu.DropDownItems.Add("Save As", null, SaveFileAs);
fileMenu.DropDownItems.Add("Exit", null, (s, e) => this.Close());
menu.Items.Add(fileMenu);
// Edit menu
var editMenu = new ToolStripMenuItem("Edit");
editMenu.DropDownItems.Add("Cut", null, (s, e) => textArea.Cut());
editMenu.DropDownItems.Add("Copy", null, (s, e) => textArea.Copy());
editMenu.DropDownItems.Add("Paste", null, (s, e) => textArea.Paste());
menu.Items.Add(editMenu);
// Format menu
var formatMenu = new ToolStripMenuItem("Format");
formatMenu.DropDownItems.Add("Change Font", null, ChangeFont);
formatMenu.DropDownItems.Add("Change Colors", null, ChangeColors);
menu.Items.Add(formatMenu);
// Help menu
var helpMenu = new ToolStripMenuItem("Help");
helpMenu.DropDownItems.Add("About", null, (s, e) =>
{
MessageBox.Show("System32 Notepad\nCreated by System32\n2025", "About");
});
menu.Items.Add(helpMenu);
}
private void OpenFile(object sender, EventArgs e)
{
var dialog = new OpenFileDialog();
dialog.Filter = "Text Files|*.txt|All Files|*.*";
if (dialog.ShowDialog() == DialogResult.OK)
{
textArea.Text = File.ReadAllText(dialog.FileName);
currentFile = dialog.FileName;
}
}
private void SaveFile(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(currentFile))
SaveFileAs(sender, e);
else
File.WriteAllText(currentFile, textArea.Text);
}
private void SaveFileAs(object sender, EventArgs e)
{
var dialog = new SaveFileDialog();
dialog.Filter = "Text Files|*.txt|All Files|*.*";
if (dialog.ShowDialog() == DialogResult.OK)
{
File.WriteAllText(dialog.FileName, textArea.Text);
currentFile = dialog.FileName;
}
}
private void ChangeFont(object sender, EventArgs e)
{
var dialog = new FontDialog();
if (dialog.ShowDialog() == DialogResult.OK)
textArea.Font = dialog.Font;
}
private void ChangeColors(object sender, EventArgs e)
{
var dialog = new ColorDialog();
if (dialog.ShowDialog() == DialogResult.OK)
textArea.ForeColor = dialog.Color;
dialog = new ColorDialog();
if (dialog.ShowDialog() == DialogResult.OK)
textArea.BackColor = dialog.Color;
}
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Notepad());
}
}
}