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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
| #pragma once
namespace redactor {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Сводка для Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: добавьте код конструктора
//
}
protected:
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ textBox1;
protected:
private: System::Windows::Forms::MenuStrip^ menuStrip1;
private: System::Windows::Forms::ToolStripMenuItem^ файлToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ создатьToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ открытьToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ сохранитьToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ сохранитьКакToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ выходToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ форматToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ правкаToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ сервисToolStripMenuItem;
private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;
private: System::Windows::Forms::SaveFileDialog^ saveFileDialog1;
private: System::Windows::Forms::ToolStripMenuItem^ шрифтToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ цветToolStripMenuItem;
private: System::Windows::Forms::FontDialog^ fontDialog1;
private: System::Windows::Forms::ColorDialog^ colorDialog1;
private: System::Windows::Forms::ToolStripMenuItem^ вырезатьToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ копироватьToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ вставитьToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ выделитьВсеToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ числоваяПроверкаToolStripMenuItem;
private:
/// <summary>
/// Требуется переменная конструктора.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Обязательный метод для поддержки конструктора - не изменяйте
/// содержимое данного метода при помощи редактора кода.
/// </summary>
void InitializeComponent(void)
{
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
this->файлToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->создатьToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->открытьToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->сохранитьToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->сохранитьКакToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->выходToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->форматToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->шрифтToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->цветToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->правкаToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->вырезатьToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->копироватьToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->вставитьToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->выделитьВсеToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->сервисToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->числоваяПроверкаToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
this->saveFileDialog1 = (gcnew System::Windows::Forms::SaveFileDialog());
this->fontDialog1 = (gcnew System::Windows::Forms::FontDialog());
this->colorDialog1 = (gcnew System::Windows::Forms::ColorDialog());
this->menuStrip1->SuspendLayout();
this->SuspendLayout();
//
// textBox1
//
this->textBox1->Dock = System::Windows::Forms::DockStyle::Fill;
this->textBox1->Location = System::Drawing::Point(0, 24);
this->textBox1->Multiline = true;
this->textBox1->Name = L"textBox1";
this->textBox1->ScrollBars = System::Windows::Forms::ScrollBars::Both;
this->textBox1->Size = System::Drawing::Size(279, 176);
this->textBox1->TabIndex = 0;
this->textBox1->Text = L"«Спасибо за использование нашего редактора!»";
//
// menuStrip1
//
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {this->файлToolStripMenuItem,
this->форматToolStripMenuItem, this->правкаToolStripMenuItem, this->сервисToolStripMenuItem});
this->menuStrip1->Location = System::Drawing::Point(0, 0);
this->menuStrip1->Name = L"menuStrip1";
this->menuStrip1->Size = System::Drawing::Size(279, 24);
this->menuStrip1->TabIndex = 1;
this->menuStrip1->Text = L"menuStrip1";
//
// файлToolStripMenuItem
//
this->файлToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(5) {this->создатьToolStripMenuItem,
this->открытьToolStripMenuItem, this->сохранитьToolStripMenuItem, this->сохранитьКакToolStripMenuItem, this->выходToolStripMenuItem});
this->файлToolStripMenuItem->Name = L"файлToolStripMenuItem";
this->файлToolStripMenuItem->Size = System::Drawing::Size(48, 20);
this->файлToolStripMenuItem->Text = L"Файл";
//
// создатьToolStripMenuItem
//
this->создатьToolStripMenuItem->Name = L"создатьToolStripMenuItem";
this->создатьToolStripMenuItem->Size = System::Drawing::Size(153, 22);
this->создатьToolStripMenuItem->Text = L"Создать";
this->создатьToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::создатьToolStripMenuItem_Click);
//
// открытьToolStripMenuItem
//
this->открытьToolStripMenuItem->Name = L"открытьToolStripMenuItem";
this->открытьToolStripMenuItem->Size = System::Drawing::Size(153, 22);
this->открытьToolStripMenuItem->Text = L"Открыть";
this->открытьToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::открытьToolStripMenuItem_Click);
//
// сохранитьToolStripMenuItem
//
this->сохранитьToolStripMenuItem->Name = L"сохранитьToolStripMenuItem";
this->сохранитьToolStripMenuItem->Size = System::Drawing::Size(153, 22);
this->сохранитьToolStripMenuItem->Text = L"Сохранить";
this->сохранитьToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::сохранитьToolStripMenuItem_Click);
//
// сохранитьКакToolStripMenuItem
//
this->сохранитьКакToolStripMenuItem->Name = L"сохранитьКакToolStripMenuItem";
this->сохранитьКакToolStripMenuItem->Size = System::Drawing::Size(153, 22);
this->сохранитьКакToolStripMenuItem->Text = L"Сохранить как";
this->сохранитьКакToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::сохранитьКакToolStripMenuItem_Click);
//
// выходToolStripMenuItem
//
this->выходToolStripMenuItem->Name = L"выходToolStripMenuItem";
this->выходToolStripMenuItem->Size = System::Drawing::Size(153, 22);
this->выходToolStripMenuItem->Text = L"Выход";
this->выходToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::выходToolStripMenuItem_Click);
//
// форматToolStripMenuItem
//
this->форматToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->шрифтToolStripMenuItem,
this->цветToolStripMenuItem});
this->форматToolStripMenuItem->Name = L"форматToolStripMenuItem";
this->форматToolStripMenuItem->Size = System::Drawing::Size(62, 20);
this->форматToolStripMenuItem->Text = L"Формат";
//
// шрифтToolStripMenuItem
//
this->шрифтToolStripMenuItem->ForeColor = System::Drawing::SystemColors::ControlText;
this->шрифтToolStripMenuItem->Name = L"шрифтToolStripMenuItem";
this->шрифтToolStripMenuItem->Size = System::Drawing::Size(113, 22);
this->шрифтToolStripMenuItem->Text = L"Шрифт";
this->шрифтToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::шрифтToolStripMenuItem_Click);
//
// цветToolStripMenuItem
//
this->цветToolStripMenuItem->ForeColor = System::Drawing::SystemColors::ActiveCaptionText;
this->цветToolStripMenuItem->Name = L"цветToolStripMenuItem";
this->цветToolStripMenuItem->Size = System::Drawing::Size(113, 22);
this->цветToolStripMenuItem->Text = L"Цвет";
this->цветToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::цветToolStripMenuItem_Click);
//
// правкаToolStripMenuItem
//
this->правкаToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {this->вырезатьToolStripMenuItem,
this->копироватьToolStripMenuItem, this->вставитьToolStripMenuItem, this->выделитьВсеToolStripMenuItem});
this->правкаToolStripMenuItem->Name = L"правкаToolStripMenuItem";
this->правкаToolStripMenuItem->Size = System::Drawing::Size(59, 20);
this->правкаToolStripMenuItem->Text = L"Правка";
//
// вырезатьToolStripMenuItem
//
this->вырезатьToolStripMenuItem->Name = L"вырезатьToolStripMenuItem";
this->вырезатьToolStripMenuItem->Size = System::Drawing::Size(148, 22);
this->вырезатьToolStripMenuItem->Text = L"Вырезать";
this->вырезатьToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::вырезатьToolStripMenuItem_Click);
//
// копироватьToolStripMenuItem
//
this->копироватьToolStripMenuItem->Name = L"копироватьToolStripMenuItem";
this->копироватьToolStripMenuItem->Size = System::Drawing::Size(148, 22);
this->копироватьToolStripMenuItem->Text = L"Копировать";
this->копироватьToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::копироватьToolStripMenuItem_Click);
//
// вставитьToolStripMenuItem
//
this->вставитьToolStripMenuItem->Name = L"вставитьToolStripMenuItem";
this->вставитьToolStripMenuItem->Size = System::Drawing::Size(148, 22);
this->вставитьToolStripMenuItem->Text = L"Вставить";
this->вставитьToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::вставитьToolStripMenuItem_Click);
//
// выделитьВсеToolStripMenuItem
//
this->выделитьВсеToolStripMenuItem->Name = L"выделитьВсеToolStripMenuItem";
this->выделитьВсеToolStripMenuItem->Size = System::Drawing::Size(148, 22);
this->выделитьВсеToolStripMenuItem->Text = L"Выделить все";
this->выделитьВсеToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::выделитьВсеToolStripMenuItem_Click);
//
// сервисToolStripMenuItem
//
this->сервисToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->числоваяПроверкаToolStripMenuItem});
this->сервисToolStripMenuItem->Name = L"сервисToolStripMenuItem";
this->сервисToolStripMenuItem->Size = System::Drawing::Size(59, 20);
this->сервисToolStripMenuItem->Text = L"Сервис";
//
// числоваяПроверкаToolStripMenuItem
//
this->числоваяПроверкаToolStripMenuItem->Name = L"числоваяПроверкаToolStripMenuItem";
this->числоваяПроверкаToolStripMenuItem->Size = System::Drawing::Size(182, 22);
this->числоваяПроверкаToolStripMenuItem->Text = L"Числовая проверка";
//
// openFileDialog1
//
this->openFileDialog1->FileName = L"openFileDialog1";
this->openFileDialog1->Filter = L"txt files (*.txt)|*.txt|All files (*.*)|*.*";
this->openFileDialog1->RestoreDirectory = true;
//
// saveFileDialog1
//
this->saveFileDialog1->Filter = L"txt files (*.txt)|*.txt|All files (*.*)|*.*";
this->saveFileDialog1->RestoreDirectory = true;
//
// fontDialog1
//
this->fontDialog1->Color = System::Drawing::Color::Gray;
//
// colorDialog1
//
this->colorDialog1->AnyColor = true;
this->colorDialog1->FullOpen = true;
this->colorDialog1->ShowHelp = true;
this->colorDialog1->SolidColorOnly = true;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(279, 200);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->menuStrip1);
this->MainMenuStrip = this->menuStrip1;
this->Name = L"Form1";
this->Text = L"Form1";
this->FormClosing += gcnew System::Windows::Forms::FormClosingEventHandler(this, &Form1::Form1_FormClosing);
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->menuStrip1->ResumeLayout(false);
this->menuStrip1->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
///////////////////////Выход
private: System::Void выходToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
Close();
}
///////////////////////Создание нового файла
private: System::Void создатьToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
textBox1->Clear();
openFileDialog1->FileName = "";
Text = "Безымянный";
}
////////////////////////Открытие файла
private: System::Void открытьToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
System::IO::Stream^ myStream;
if (openFileDialog1->ShowDialog()==System::Windows::Forms::DialogResult::OK )
if ( (myStream = openFileDialog1->OpenFile()) != nullptr ){
//читаем данные из потока, связанного с файлом
System::IO::StreamReader ^sr = gcnew System::IO::StreamReader(myStream);
textBox1->Text = sr->ReadToEnd();
sr->Close();
myStream->Close();
}
else
MessageBox::Show("Произошла ошибка при октрытии файла");
}
//////////////////Сохранить файл с вводом имени
private: System::Void сохранитьКакToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
System::IO::Stream^ myStream;
if ( saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
if ( (myStream = saveFileDialog1->OpenFile()) != nullptr ) {
//пишем данные в поток, связанный с файлом
System::IO::StreamWriter ^sw = gcnew System::IO::StreamWriter(myStream);
sw->Write(textBox1->Text);
sw->Close();
myStream->Close();
Text = saveFileDialog1->FileName;
}
else
MessageBox::Show("Произошла ошибка при открытии файла");
}
////////////////////////Сохранить файл под своим именем
private: System::Void сохранитьToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
if (Text=="Безымянный")
//если имени нет, вызываем функцию сохранения с вводом имени
сохранитьКакToolStripMenuItem_Click(sender,e);
else {
System::IO::StreamWriter ^sw = gcnew System::IO::StreamWriter(Text);
sw->Write(textBox1->Text);
sw->Close();
}
}
///////////////выбор шрифта
private: System::Void шрифтToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
fontDialog1->Font = textBox1->Font;
if (fontDialog1->ShowDialog()==System::Windows::Forms::DialogResult::OK) {
textBox1->Font = fontDialog1->Font;
}
}
///////////////выбор цвета
private: System::Void цветToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
colorDialog1->Color = textBox1->BackColor;
if (colorDialog1->ShowDialog()==System::Windows::Forms::DialogResult::OK) {
textBox1->BackColor = colorDialog1->Color;
}
}
private: System::Void вырезатьToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
{
textBox1->Cut();
}
private: System::Void копироватьToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
{
textBox1->Copy();
}
private: System::Void вставитьToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
{
textBox1->Paste();
}
private: System::Void выделитьВсеToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
{
textBox1->SelectAll();
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
Text="Безымянный";
}
private: System::Void Form1_FormClosed(System::Object^ sender, System::Windows::Forms::FormClosedEventArgs^ e)
{
}
private: System::Void Form1_FormClosing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e)
{
if (textBox1->Modified == false) return;
auto MeBox = MessageBox::Show("Текст был изменён. \nСохранить изменения?","Простой редактор", MessageBoxButtons::YesNoCancel, MessageBoxIcon::Exclamation);
if (MeBox == Windows::Forms::DialogResult::No) return;
if (MeBox == Windows::Forms::DialogResult::Cancel) e->Cancel=true;
if (MeBox == Windows::Forms::DialogResult::Yes) сохранитьToolStripMenuItem_Click(sender, e);
}
}; |