Skip to content

Commit a0cfa78

Browse files
committed
Условие задачи:
Написать приложение, которое отображает количество текста, прочитанного из файла с помощью ProgressBar.
1 parent aaf6f17 commit a0cfa78

File tree

12 files changed

+822
-0
lines changed

12 files changed

+822
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.23107.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hometask-1", "Hometask-1\Hometask-1.csproj", "{06D54DB2-5DF5-464B-88DF-B50CD95D28F7}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{06D54DB2-5DF5-464B-88DF-B50CD95D28F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{06D54DB2-5DF5-464B-88DF-B50CD95D28F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{06D54DB2-5DF5-464B-88DF-B50CD95D28F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{06D54DB2-5DF5-464B-88DF-B50CD95D28F7}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
5+
</startup>
6+
</configuration>

Homeworks/ShagSchool/Window-Forms/Lesson-2/Hometasks/Hometask-1/Hometask-1/FormMain.Designer.cs

Lines changed: 153 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
using System.IO;
11+
12+
namespace Hometask_1
13+
{
14+
public partial class FormMain : Form
15+
{
16+
//ПОЛЯ КЛАССА
17+
//+-------------------------------------------------------------------+
18+
19+
string pathToFile = null; //путь к оригиналу файла
20+
string pathToFolder = null; //путь для сохранения нового файла
21+
22+
23+
//КОНСТРУКТРЫ КЛАССА
24+
//+-------------------------------------------------------------------+
25+
26+
public FormMain()
27+
{
28+
InitializeComponent();
29+
}
30+
31+
32+
//ОБРАБОТЧИКИ СОБЫТИЙ КЛАССА
33+
//+-------------------------------------------------------------------+
34+
35+
/// <summary>
36+
/// Обработка события клика на поле "Путь к файлу"
37+
/// </summary>
38+
private void TextBoxFileDirectoryOpenClick(Object sender, EventArgs e)
39+
{
40+
DialogResult result = openFileDialog.ShowDialog();
41+
if(result == DialogResult.OK)
42+
{
43+
if (this.pathToFile != null) this.pathToFile = null;
44+
this.pathToFile = this.openFileDialog.FileName;
45+
this.textBoxFileDirectoryOpen.Text = this.openFileDialog.FileName;
46+
}
47+
else
48+
{
49+
this.pathToFile = null;
50+
this.openFileDialog.Dispose();
51+
}
52+
}
53+
/// <summary>
54+
/// Обработка события клика на поле "Путь сохранения файла"
55+
/// </summary>
56+
private void TextBoxFileDirectorySaveClick(Object sender, EventArgs e)
57+
{
58+
DialogResult result = folderBrowserDialog.ShowDialog();
59+
if(result == DialogResult.OK)
60+
{
61+
if (this.pathToFolder != null) this.pathToFolder = null;
62+
this.pathToFolder = this.folderBrowserDialog.SelectedPath;
63+
this.textBoxFileDirectorySave.Text = this.folderBrowserDialog.SelectedPath;
64+
}
65+
else
66+
{
67+
this.pathToFolder = null;
68+
this.folderBrowserDialog.Dispose();
69+
}
70+
}
71+
72+
/// <summary>
73+
/// Обработка события нажатия кнопки "копировать"
74+
/// </summary>
75+
private void buttonCopyClick(Object sender, EventArgs e)
76+
{
77+
this.CopyFile();
78+
MessageBox.Show("Копирования завершено");
79+
this.SetProgressBarDefault();
80+
this.SetTextBoxsDefault();
81+
}
82+
/// <summary>
83+
/// Обработка события нажатия кнопки "выйти"
84+
/// </summary>
85+
private void buttonExitClick(Object sender, EventArgs e)
86+
{
87+
this.Close();
88+
this.Dispose();
89+
}
90+
91+
92+
//МЕТОДЫ КЛАССА
93+
//+-------------------------------------------------------------------+
94+
95+
/// <summary>
96+
/// Копирование файла в указанную пользователем директорию.
97+
/// Процесс копирования отображается в прогресс баре окна.
98+
/// </summary>
99+
private void CopyFile()
100+
{
101+
string originalFileName = Path.GetFileName(this.pathToFile);
102+
string fileSaveDirectory = Path.Combine(this.pathToFolder, originalFileName);
103+
FileStream originalFile = new FileStream(this.pathToFile, FileMode.Open, FileAccess.Read);
104+
FileStream copiedFile = new FileStream(fileSaveDirectory, FileMode.CreateNew, FileAccess.Write);
105+
this.progressBarFileCoping.Minimum = 0;
106+
this.progressBarFileCoping.Maximum = (int)originalFile.Length - 1;
107+
while (originalFile.Position < originalFile.Length)
108+
{
109+
this.progressBarFileCoping.Value = (int)originalFile.Position;
110+
copiedFile.WriteByte((Byte)originalFile.ReadByte());
111+
}
112+
if (originalFile != null) originalFile.Close();
113+
if (copiedFile != null) copiedFile.Close();
114+
}
115+
/// <summary>
116+
/// Сброс значения прогресс бара
117+
/// </summary>
118+
void SetProgressBarDefault()
119+
{
120+
this.progressBarFileCoping.Value = 0;
121+
this.progressBarFileCoping.Minimum = 0;
122+
this.progressBarFileCoping.Maximum = 0;
123+
}
124+
/// <summary>
125+
/// Сброс значений полей для ввода текста
126+
/// </summary>
127+
void SetTextBoxsDefault()
128+
{
129+
this.textBoxFileDirectoryOpen.Text = null;
130+
this.textBoxFileDirectorySave.Text = null;
131+
}
132+
}
133+
}

0 commit comments

Comments
 (0)