-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
277 lines (234 loc) · 7.44 KB
/
Form1.cs
File metadata and controls
277 lines (234 loc) · 7.44 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
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
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;
using System.IO;
namespace LogPad
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// Titles Of Buttons
ToolTip Title = new ToolTip();
private void OpenButton_MouseHover(object sender, EventArgs e)
{
Title.SetToolTip(OpenButton, "Open File");
}
private void SaveButton_MouseHover(object sender, EventArgs e)
{
Title.SetToolTip(SaveButton, "Save");
}
private void PrintButton_MouseHover(object sender, EventArgs e)
{
Title.SetToolTip(PrintButton, "Print");
}
private void CopyButton_MouseHover(object sender, EventArgs e)
{
Title.SetToolTip(CopyButton, "Copy");
}
private void PasteButton_MouseHover(object sender, EventArgs e)
{
Title.SetToolTip(PasteButton, "Paste");
}
private void CutButton_MouseHover(object sender, EventArgs e)
{
Title.SetToolTip(CutButton, "Cut");
}
private void SelectAllButton_MouseHover(object sender, EventArgs e)
{
Title.SetToolTip(SelectAllButton, "Select All");
}
private void Undo_MouseHover(object sender, EventArgs e)
{
Title.SetToolTip(Undo, "Undo");
}
private void Redo_MouseHover(object sender, EventArgs e)
{
Title.SetToolTip(Redo, "Redo");
}
private void Ltr_MouseHover(object sender, EventArgs e)
{
Title.SetToolTip(Ltr, "Left to Right");
}
private void Rtl_MouseHover(object sender, EventArgs e)
{
Title.SetToolTip(Rtl, "Right to Left");
}
private void WordWrapButton_MouseHover(object sender, EventArgs e)
{
Title.SetToolTip(WordWrapButton, "Word Wrap");
}
private void CounterToggle_MouseHover(object sender, EventArgs e)
{
if (CounterVisible)
{
Title.SetToolTip(CounterToggle, "Hide Counter");
}
else
{
Title.SetToolTip(CounterToggle, "Show Counter");
}
}
string FilePath = String.Empty;
// Open File
private void OpenButton_Click(object sender, EventArgs e)
{
var Open = new OpenFileDialog();
Open.Filter = "Logs Files|*.log";
Open.FileName = "" + ".log";
var Result = Open.ShowDialog();
if (Result == DialogResult.OK)
{
FilePath = Open.FileName;
TextBox.Text = File.ReadAllText(FilePath);
LengthCounter();
}
}
// Save File
private void SaveButton_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(FilePath))
{
var Dialog = new SaveFileDialog();
Dialog.Filter = "Logs Files|*.log";
Dialog.FileName = "" + ".log";
var Result = Dialog.ShowDialog();
if (Result == DialogResult.OK)
{
File.WriteAllText(Dialog.FileName, TextBox.Text);
FilePath = Dialog.FileName;
}
}
else
{
var FileWrite = new StreamWriter(FilePath);
FileWrite.WriteLine(TextBox.Text);
FileWrite.Close();
MessageBox.Show("Saved!");
}
}
// Print File
private void PrintButton_Click(object sender, EventArgs e)
{
PrintPreviewDialog.Show();
}
private void PrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawString(TextBox.Text, TextBox.Font, Brushes.Black, new Point(100, 100));
}
// Copy
private void CopyButton_Click(object sender, EventArgs e)
{
Clipboard.Clear();
TextBox.Copy();
}
// Paste
private void PasteButton_Click(object sender, EventArgs e)
{
TextBox.Paste();
}
// Cut
private void CutButton_Click(object sender, EventArgs e)
{
Clipboard.Clear();
TextBox.Cut();
}
// SelectAll
private void SelectAllButton_Click(object sender, EventArgs e)
{
TextBox.SelectAll();
TextBox.Focus();
}
// Undo
private void Undo_Click(object sender, EventArgs e)
{
TextBox.Undo();
}
// Redo
private void Redo_Click(object sender, EventArgs e)
{
TextBox.Redo();
}
// Ltr
private void Ltr_Click(object sender, EventArgs e)
{
TextBox.RightToLeft = RightToLeft.No;
Ltr.FlatStyle = FlatStyle.Standard;
Rtl.FlatStyle = FlatStyle.Flat;
}
// Rtl
private void Rtl_Click(object sender, EventArgs e)
{
TextBox.RightToLeft = RightToLeft.Yes;
Rtl.FlatStyle = FlatStyle.Standard;
Ltr.FlatStyle = FlatStyle.Flat;
}
// WordWrap
bool actvated = false;
private void WordWrapButton_Click(object sender, EventArgs e)
{
if (actvated)
{
TextBox.WordWrap = false;
actvated = false;
WordWrapButton.FlatStyle = FlatStyle.Flat;
}
else
{
TextBox.WordWrap = true;
actvated = true;
WordWrapButton.FlatStyle = FlatStyle.Standard;
}
}
// Counter
void LengthCounter()
{
int c = 0, l = 0;
foreach (char T in TextBox.Text)
{
if (T == ' ' || T == '\t')
{
continue;
}
c += 1;
if (T == '\n')
{
l += 1;
c -= 1;
}
}
LengthNumber.Text = Convert.ToString(TextBox.Text.Length);
CharactersNumber.Text = c.ToString();
LinesNumber.Text = l.ToString();
}
private void TextBox_KeyUp(object sender, KeyEventArgs e)
{
LengthCounter();
}
// CounterToggle
bool CounterVisible = false;
private void CounterToggle_Click(object sender, EventArgs e)
{
if (CounterVisible)
{
Counter.Visible = false;
CounterToggle.FlatStyle = FlatStyle.Flat;
CounterVisible = false;
}
else
{
Counter.Visible = true;
CounterToggle.FlatStyle = FlatStyle.Standard;
CounterVisible = true;
}
}
}
}