This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
195 lines (161 loc) · 6.08 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Printing;
namespace NVGNotes
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ActualFont = new Font(defaultFont, defaultFontSize);
}
public string defaultFont = "Albert Sans";
public int defaultFontSize = 10;
public FontStyle defaultFontStyle = FontStyle.Regular;
public Font ActualFont { get; set; }
private void clearButton_Click(object sender, EventArgs e)
{
textBox.Text = string.Empty;
}
private void aboutToolStripMenuItem1_Click(object sender, EventArgs e)
{
textBox.Text = string.Empty;
}
private void Form1_Load(object sender, EventArgs e)
{
FontFamily defaultFontFamily = new FontFamily(defaultFont);
textBox.Font = new Font(defaultFontFamily, defaultFontSize, defaultFontStyle);
}
private void boldButton_Click(object sender, EventArgs e)
{
defaultFontStyle = FontStyle.Bold;
FontFamily defaultFontFamily = new FontFamily(defaultFont);
textBox.Font = new Font(defaultFontFamily, defaultFontSize, defaultFontStyle);
}
private void italicButton_Click(object sender, EventArgs e)
{
defaultFontStyle = FontStyle.Italic;
FontFamily defaultFontFamily = new FontFamily(defaultFont);
textBox.Font = new Font(defaultFontFamily, defaultFontSize, defaultFontStyle);
}
private void boldToolStripMenuItem_Click(object sender, EventArgs e)
{
defaultFontStyle = FontStyle.Bold;
FontFamily defaultFontFamily = new FontFamily(defaultFont);
textBox.Font = new Font(defaultFontFamily, defaultFontSize, defaultFontStyle);
}
private void italicToolStripMenuItem_Click(object sender, EventArgs e)
{
defaultFontStyle = FontStyle.Italic;
FontFamily defaultFontFamily = new FontFamily(defaultFont);
textBox.Font = new Font(defaultFontFamily, defaultFontSize, defaultFontStyle);
}
private void underlineBTN_Click(object sender, EventArgs e)
{
defaultFontStyle = FontStyle.Underline;
FontFamily defaultFontFamily = new FontFamily(defaultFont);
textBox.Font = new Font(defaultFontFamily, defaultFontSize, defaultFontStyle);
}
private void underlineToolStripMenuItem_Click(object sender, EventArgs e)
{
defaultFontStyle = FontStyle.Underline;
FontFamily defaultFontFamily = new FontFamily(defaultFont);
textBox.Font = new Font(defaultFontFamily, defaultFontSize, defaultFontStyle);
}
private void resetButton_Click(object sender, EventArgs e)
{
defaultFontStyle = FontStyle.Regular;
FontFamily defaultFontFamily = new FontFamily(defaultFont);
textBox.Font = new Font(defaultFontFamily, defaultFontSize, defaultFontStyle);
}
private void fontSize_ValueChanged(object sender, EventArgs e)
{
defaultFontSize = Convert.ToInt32(Math.Round(fontSize.Value, 0));
FontFamily defaultFontFamily = new FontFamily(defaultFont);
textBox.Font = new Font(defaultFontFamily, defaultFontSize, defaultFontStyle);
}
private void aboutNVGNotesToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFile = new SaveFileDialog();
// Set the initial directory and file name filter
saveFile.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
saveFile.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
// Show the save file dialog and check if the user clicked the "OK" button
if (saveFile.ShowDialog() == DialogResult.OK)
{
// Get the selected file name
string fileName = saveFile.FileName;
try
{
// Save the contents of the textBox to the selected file
File.WriteAllText(fileName, textBox.Text);
MessageBox.Show("File saved successfully!");
}
catch (Exception ex)
{
MessageBox.Show("Error saving file: " + ex.Message);
}
}
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
// Set the initial directory and file name filter
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
openFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
// Show the open file dialog and check if the user clicked the "OK" button
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
// Get the selected file name
string fileName = openFileDialog.FileName;
try
{
// Read the contents of the selected file
string fileContents = File.ReadAllText(fileName);
// Display the file contents in the textBox
textBox.Text = fileContents;
MessageBox.Show("File opened successfully!");
}
catch (Exception ex)
{
MessageBox.Show("Error opening file: " + ex.Message);
}
}
}
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
PrintDialog printDialog = new PrintDialog();
// Set the PrintDocument instance for the print dialog
PrintDocument printDocument = new PrintDocument();
printDialog.Document = printDocument;
// Show the print dialog and check if the user clicked the "OK" button
if (printDialog.ShowDialog() == DialogResult.OK)
{
// Set the PrintPage event handler for the PrintDocument
printDocument.PrintPage += PrintDocument_PrintPage;
// Start the printing process
printDocument.Print();
}
}
private void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
{
// Get the text from the textBox control
string textToPrint = textBox.Text;
// Create a font and calculate the size of the text
Font font = new Font(defaultFont, defaultFontSize, defaultFontStyle);
SizeF textSize = e.Graphics.MeasureString(textToPrint, font);
// Calculate the printable area of the page
RectangleF printArea = new RectangleF(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, e.MarginBounds.Height);
// Print the text within the printable area
e.Graphics.DrawString(textToPrint, font, Brushes.Black, printArea);
// Check if there are more pages to print
e.HasMorePages = false;
}
}
}