-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
175 lines (159 loc) · 5.74 KB
/
Copy pathForm1.cs
File metadata and controls
175 lines (159 loc) · 5.74 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
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;
namespace Утилита_создания_файлов
{
public partial class Form1 : Form
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
OpenFileDialog open = new OpenFileDialog();
Random rand = new Random();
public string messege;
public string patch = @"README.txt"; //Путь до файла
public Form1()
{
InitializeComponent();
saveFileDialog1.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*";
open.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*";
}
private void DevolopToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("Собственность Паши Razor_Z_Pi",
"Developer",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
}
private void SaveFileToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.Cancel)
return;
// получаем выбранный файл
string filename = saveFileDialog1.FileName;
// сохраняем текст в файл
System.IO.File.Create(filename).Close();
MessageBox.Show("Файл сохранен");
label1.Text = filename;
messege = filename;
}
private void Button2_Click(object sender, EventArgs e)
{
progressBar1.Value = 0;
int number = 100;
textBox1.Text = "";
if (textBox1.Text == "" || textBox1.Text == " ")
{
for (int i = 0; i < number; i++)
{
progressBar1.Value++;
}
}
}
private void Button3_Click(object sender, EventArgs e)
{
textBox1.Text = "";
int n = Int32.Parse(comboBox1.Text);
for (int i = 0; i < n; i++)
{
textBox1.Text += rand.Next(1, 10).ToString();
}
}
private void Button1_Click(object sender, EventArgs e)
{
Push();
}
private void Button4_Click(object sender, EventArgs e)
{
if (open.ShowDialog() == DialogResult.Cancel)
return;
messege = open.FileName;
label1.Text = open.FileName;
}
private void Form1_Load(object sender, EventArgs e)
{
MaximizeBox = false;
}
private void Push()
{
int number = 100;
progressBar1.Value = 0;
if (label1.Text == "")
{
MessageBox.Show("Файл не выбран",
"Внимание",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
return;
}
if (messege != "")
{
if (textBox1.Text != "")
{
for (int i = 0; i < number; i++)
{
progressBar1.Value++;
}
}
try
{
// сохраняем текст в файл
System.IO.File.AppendAllText(messege, textBox1.Text + "\n");
MessageBox.Show("Запись выполнена!!!",
"Ура",
MessageBoxButtons.OK,
MessageBoxIcon.Asterisk);
progressBar1.Value = 0;
}
catch (Exception ex)
{
MessageBox.Show("Поле не должно быть пустым!!!",
"Внимание",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
}
}
}
// Для Enter, чтобы при нажатие клавиши выполнялась запись
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Push();
}
}
private void ОчиститьФайлToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
string S_T = label1.Text;
System.IO.File.Create(messege).Close();
MessageBox.Show($"Файл {S_T} полностью очищен!!!",
"Внимание",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
catch (Exception ex)
{
MessageBox.Show($"Файл не выбран, пожалуйста выберите его",
"Внимание",
MessageBoxButtons.OK,
MessageBoxIcon.Hand);
}
}
private void ОчиститьПутьФайлаToolStripMenuItem_Click(object sender, EventArgs e)
{
messege = "";
label1.Text = "";
}
private void СправкаToolStripMenuItem_Click(object sender, EventArgs e)
{
//Открыть через блокнот:
System.Diagnostics.Process.Start("notepad.exe", patch);
}
}
}