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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
| 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 Word = Microsoft.Office.Interop.Word;
using System.IO;
namespace Text_Editor_Arkadiy
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string filename, name;
int count = 1;
bool switcher, switcher1;
List<TabPage> TP = new List<TabPage>();
List<RichTextBox> RTB = new List<RichTextBox>();
private void Form1_Load(object sender, EventArgs e)
{
openFileDialog1.Filter = "Текстовый файл|*.txt|Документ word|*.docx";
// RegistryKey regkey = Registry.CurrentUser;
//RegistryKey key = regkey.OpenSubKey("ProstoPapka");
//this.Width = Convert.ToInt32(key.GetValue("Ширина окна"));
//this.Height = Convert.ToInt32(key.GetValue("Высота окна"));
// key.Close();
}
private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
}
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
private void toolStripLabel4_Click(object sender, EventArgs e)
{
}
private void открытьToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
filename = openFileDialog1.FileName;
name = System.IO.Path.GetFileName(filename);
TabPage NewTB = new TabPage(name);
RichTextBox RTB = new RichTextBox();
RTB.Dock = DockStyle.Fill;
tabControl1.TabPages.Add(NewTB);
NewTB.Controls.Add(RTB);
tabControl1.SelectedTab = NewTB;
RTB.BorderStyle = BorderStyle.None;
RTB.Font = new Font("Consolas", 12);
RTB.AcceptsTab = true;
count++;
string fileText = System.IO.File.ReadAllText(filename);
RTB.Text = fileText;
}
}
catch { MessageBox.Show("Error! Try again"); }
}
private void созранитьКакToolStripMenuItem_Click(object sender, EventArgs e)
{
RichTextBox rtb = (RichTextBox)tabControl1.SelectedTab.Controls[0];
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
filename = saveFileDialog1.FileName;
name = System.IO.Path.GetFileName(filename);
tabControl1.SelectedTab.Text = name;
System.IO.File.WriteAllText(filename, rtb.Text);
saveFileDialog1.DefaultExt = "*.txt";
MessageBox.Show("Saved!");
}
}
private void создатьToolStripMenuItem_Click(object sender, EventArgs e)
{
TabPage tp = new TabPage();
RichTextBox rtb = new RichTextBox();
tabControl1.Controls.Add(tp);
tp.Text = "New tab " + count;
TP.Add(tp);
RTB.Add(rtb);
count++;
tp.Controls.Add(rtb);
rtb.Width = tp.Width;
rtb.Height = tp.Height;
rtb.Dock = DockStyle.Fill;
rtb.ContextMenuStrip = contextMenuStrip1;
}
private void сохранитьToolStripMenuItem_Click(object sender, EventArgs e)
{
RichTextBox rtb = (RichTextBox)tabControl1.SelectedTab.Controls[0];
System.IO.File.WriteAllText(filename, rtb.Text);
}
private void выходToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Hide();
}
private void печатьToolStripMenuItem_Click(object sender, EventArgs e)
{
if (printDialog1.ShowDialog(this) == DialogResult.OK)
printDocument1.Print();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
RichTextBox rtb = (RichTextBox)tabControl1.SelectedTab.Controls[0];
var font = new Font("Consolas", 12, FontStyle.Bold);
e.Graphics.DrawString(rtb.Text, font, Brushes.Black, 0, 0);
}
private void закрытьToolStripMenuItem_Click(object sender, EventArgs e)
{
tabControl1.TabPages.Remove(tabControl1.SelectedTab);
}
private void закрытьВсёToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tabControl1.TabCount != 0)
{
for (int i = 0; i < count-1; i++)
{
tabControl1.TabPages.Remove(tabControl1.SelectedTab);
}
count = 0;
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
//TabPage NewTB = new TabPage("New " + count);
//RichTextBox RTB = new RichTextBox();
//
//RegistryKey regkey = Registry.CurrentUser;
//RegistryKey key = regkey.CreateSubKey("ProstoPapka");
//key.SetValue("Ширина окна", this.Width);
//key.SetValue("Высота окна", this.Height);
//key.SetValue("Вкладка", NewTB);
//key.SetValue("Цвет", this.ForeColor);
//key.Close();
}
private void отменитьToolStripMenuItem_Click(object sender, EventArgs e)
{
RichTextBox rtb = (RichTextBox)tabControl1.SelectedTab.Controls[0];
rtb.Undo();
}
private void копироватьToolStripMenuItem_Click(object sender, EventArgs e)
{
RichTextBox rtb = (RichTextBox)tabControl1.SelectedTab.Controls[0];
rtb.Copy();
}
private void вставитьToolStripMenuItem_Click(object sender, EventArgs e)
{
RichTextBox rtb = (RichTextBox)tabControl1.SelectedTab.Controls[0];
rtb.Paste();
}
private void удалитьToolStripMenuItem1_Click(object sender, EventArgs e)
{
RichTextBox rtb = (RichTextBox)tabControl1.SelectedTab.Controls[0];
rtb.SelectedText = "";
}
private void ввыделитьВсёToolStripMenuItem_Click(object sender, EventArgs e)
{
RichTextBox rtb = (RichTextBox)tabControl1.SelectedTab.Controls[0];
rtb.SelectAll();
}
private void времяИДатаToolStripMenuItem_Click(object sender, EventArgs e)
{
RichTextBox rtb = (RichTextBox)tabControl1.SelectedTab.Controls[0];
rtb.SelectedText = DateTime.Now.ToString();
}
private void шрифтToolStripMenuItem_Click(object sender, EventArgs e)
{
RichTextBox rtb = (RichTextBox)tabControl1.SelectedTab.Controls[0];
if (fontDialog1.ShowDialog() == DialogResult.OK)
{
rtb.SelectionFont = fontDialog1.Font;
}
}
private void tabControl1_MouseClick(object sender, MouseEventArgs e)
{
}
private void цветToolStripMenuItem_Click(object sender, EventArgs e)
{
RichTextBox rtb = (RichTextBox)tabControl1.SelectedTab.Controls[0];
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
rtb.SelectionColor = colorDialog1.Color;
}
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
RichTextBox rtb = (RichTextBox)tabControl1.SelectedTab.Controls[0];
if (switcher == false)
{
rtb.SelectionFont = new Font(rtb.Font, FontStyle.Bold);
switcher = true;
}
else
{
rtb.SelectionFont = new Font(rtb.Font, FontStyle.Regular);
switcher = false;
}
}
private void toolStripComboBox2_Click(object sender, EventArgs e)
{
foreach (FontFamily item in FontFamily.Families)
{
toolStripComboBox2.Items.Add(item.Name.ToString());
}
}
private void toolStripComboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
RichTextBox rtb = (RichTextBox)tabControl1.SelectedTab.Controls[0];
if (toolStripComboBox2.SelectedIndex != -1 && toolStripComboBox2.SelectedIndex != -1)
{
rtb.SelectionFont = new Font(toolStripComboBox2.Text, 12);
}
}
catch { };
}
private void toolStripComboBox3_Click(object sender, EventArgs e)
{
for (int i = 0; i <= 72; i++)
{
toolStripComboBox3.Items.Add(i);
}
}
private void toolStripComboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
RichTextBox rtb = (RichTextBox)tabControl1.SelectedTab.Controls[0];
if (toolStripComboBox3.SelectedIndex != -1 && toolStripComboBox3.SelectedIndex != -1)
{
rtb.SelectionFont = new Font(rtb.Font.FontFamily, float.Parse(toolStripComboBox3.Text));
}
}
catch { }
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
RichTextBox rtb = (RichTextBox)tabControl1.SelectedTab.Controls[0];
if (switcher1 == false)
{
rtb.SelectionFont = new Font(rtb.Font, FontStyle.Italic);
switcher1 = true;
}
else
{
rtb.SelectionFont = new Font(rtb.Font, FontStyle.Regular);
switcher1 = false;
}
}
private void вырезатьToolStripMenuItem_Click(object sender, EventArgs e)
{
RichTextBox rtb = (RichTextBox)tabControl1.SelectedTab.Controls[0];
rtb.Cut();
}
}
} |