Skip to content

Commit 61dfe80

Browse files
committed
Условие задачи:
УСЛОВИЕ ЗАДАЧИ: Разработайте приложение, которое состоит из двух форм. Первая форма содержит TextBox доступный только для чтения и две кнопки «загрузить файл» и «редактировать». Кнопка «редактировать» изначально неактивна. При нажатии на первую кнопку, открывается диалог и пользователю предлагают выбрать текстовый файл. Выбранный файл загружается в TextBox и кнопка «редактировать» становится активной. При нажатии на вторую кнопку открывается вторая форма (не модально), которая содержит TextBox доступный для редактирования и две кнопки «Сохранить» и «Отменить». При нажатии на первую кнопку изменения отображаются в TextBox первой формы.
1 parent c2db464 commit 61dfe80

File tree

18 files changed

+1460
-0
lines changed

18 files changed

+1460
-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-3", "Hometask-3\Hometask-3.csproj", "{9E85143B-EF85-4CEE-86C8-CDBA2FF75F77}"
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+
{9E85143B-EF85-4CEE-86C8-CDBA2FF75F77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{9E85143B-EF85-4CEE-86C8-CDBA2FF75F77}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{9E85143B-EF85-4CEE-86C8-CDBA2FF75F77}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{9E85143B-EF85-4CEE-86C8-CDBA2FF75F77}.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-3/Hometasks/Hometask-3/Hometask-3/FORMS/FormMain.Designer.cs

Lines changed: 97 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.IO;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using System.Windows.Forms;
11+
12+
namespace Hometask_3.Forms
13+
{
14+
public partial class FormMain : Form
15+
{
16+
//ПОЛЯ КЛАССА:
17+
//+-------------------------------------------------------------------+
18+
19+
private string path = null; //путь к файлу
20+
private FileStream file = null; //байтовый поток
21+
private StreamReader streamTxtRdr = null; //чтение текста из файла
22+
private FormProgressBar formProgressBar = null; //окно с прогресс баром
23+
private OpenFileDialog openFileDialog = null; //окно для откр. файла
24+
private FormTextEdit formTextEdit = null; //форма для ред. текста
25+
26+
27+
28+
//КОНСТРУКТОРЫ КЛАССА:
29+
//+-------------------------------------------------------------------+
30+
31+
/// <summary>
32+
/// Конструктор без параметров
33+
/// </summary>
34+
public FormMain()
35+
{
36+
this.InitializeComponent();
37+
this.EventSubscription();
38+
}
39+
40+
41+
42+
//МЕТОДЫ КЛАССА:
43+
//+-------------------------------------------------------------------+
44+
45+
//Создание дочерних форм//
46+
47+
/// <summary>
48+
/// Создание формы содержащей в себе ProgressBar.
49+
/// Данная форма отслеживает загрузку данных в приложение.
50+
/// </summary>
51+
private void FormProgressBarInitialization()
52+
{
53+
this.formProgressBar = new FormProgressBar(this.file,
54+
this.richTextBoxDocument);
55+
this.formProgressBar.StartPosition = FormStartPosition.CenterParent;
56+
this.formProgressBar.Owner = this;
57+
this.formProgressBar.ShowDialog(this);
58+
}
59+
60+
/// <summary>
61+
/// Создание диалогового окна для открытия пользователем, произвольного
62+
/// текстового файла
63+
/// </summary>
64+
private void OpenFileDialogInitialization()
65+
{
66+
this.openFileDialog = new OpenFileDialog();
67+
this.openFileDialog.Multiselect = false;
68+
this.openFileDialog.Title = "Открыть текстовый файл";
69+
this.openFileDialog.AddExtension = true;
70+
this.openFileDialog.CheckFileExists = true;
71+
this.openFileDialog.CheckPathExists = true;
72+
this.openFileDialog.DefaultExt = "txt";
73+
this.openFileDialog.DereferenceLinks = true;
74+
this.openFileDialog.Filter = "txt files (*.txt)|*.txt";
75+
this.openFileDialog.ShowDialog(this);
76+
}
77+
78+
/// <summary>
79+
/// Создание формы для редактирования заданного пользователем текста
80+
/// </summary>
81+
private void FormTextEditInitialization()
82+
{
83+
this.formTextEdit = new FormTextEdit(this.richTextBoxDocument);
84+
this.formTextEdit.Owner = this;
85+
this.formTextEdit.Show(this);
86+
}
87+
88+
//Подписка на события//
89+
90+
/// <summary>
91+
/// Подписка контроллеров формы на события
92+
/// </summary>
93+
private void EventSubscription()
94+
{
95+
this.buttonDownload.Click += new EventHandler(this.ButtonDownloadClick);
96+
this.buttonEdite.Click += new EventHandler(this.ButtonEditClick);
97+
}
98+
99+
100+
101+
//ОБАБОТЧИКИ СОБЫТИЙ:
102+
//+-------------------------------------------------------------------+
103+
104+
/// <summary>
105+
/// Открывает диалоговое окно "открытия файла", после чего, загружет
106+
/// выбранные файл в текстовый контроллер "RichTextBox" расположенный
107+
/// в главном окне приложения.
108+
/// </summary>
109+
private void ButtonDownloadClick(Object sender, EventArgs e)
110+
{
111+
this.OpenFileDialogInitialization();
112+
this.path = this.openFileDialog.FileName;
113+
if (!String.IsNullOrEmpty(this.path) ||
114+
!String.IsNullOrWhiteSpace(this.path))
115+
{
116+
this.file = new FileStream(this.path, FileMode.Open,
117+
FileAccess.ReadWrite);
118+
this.streamTxtRdr = new StreamReader(this.file);
119+
this.FormProgressBarInitialization();
120+
if (this.formProgressBar != null) this.formProgressBar.Dispose();
121+
this.buttonEdite.Enabled = true;
122+
if (this.streamTxtRdr != null)
123+
{
124+
this.streamTxtRdr.Close();
125+
this.streamTxtRdr = null;
126+
}
127+
if (this.file != null)
128+
{
129+
this.file.Close();
130+
this.file = null;
131+
}
132+
}
133+
if (this.openFileDialog != null)
134+
{
135+
this.openFileDialog.Dispose();
136+
this.openFileDialog = null;
137+
}
138+
}
139+
140+
/// <summary>
141+
/// Открывает окно для редактирования загруженного пользователем
142+
/// из файла текста.
143+
/// </summary>
144+
private void ButtonEditClick(Object sender, EventArgs e)
145+
{
146+
this.FormTextEditInitialization();
147+
}
148+
149+
150+
151+
//ДЕСТРУКТОР КЛАССА:
152+
//+-------------------------------------------------------------------+
153+
~FormMain()
154+
{
155+
if (this.formProgressBar != null) this.formProgressBar.Dispose();
156+
if (this.streamTxtRdr != null) this.streamTxtRdr.Close();
157+
if (this.file != null) this.file.Close();
158+
if (this.formTextEdit != null) this.formTextEdit.Dispose();
159+
}
160+
}
161+
}

0 commit comments

Comments
 (0)