From 9c27b69e17aab93a1e3b51a300d19d6c1edb93d5 Mon Sep 17 00:00:00 2001 From: Kirill <117719052+KirillFirsof@users.noreply.github.com> Date: Sun, 17 Nov 2024 13:25:39 +0400 Subject: [PATCH] lab1 --- .gitattributes | 63 ++++++++ .../HierarchicalTreeView.Designer.cs | 55 +++++++ CheckedListBoxLibrary/HierarchicalTreeView.cs | 143 ++++++++++++++++++ .../HierarchicalTreeView.resx | 120 +++++++++++++++ CheckedListBoxLibrary/MyUserControls.csproj | 10 ++ .../SmartCheckedListBox.Designer.cs | 57 +++++++ CheckedListBoxLibrary/SmartCheckedListBox.cs | 68 +++++++++ .../SmartCheckedListBox.resx | 120 +++++++++++++++ .../SmartTextBox.Designer.cs | 57 +++++++ CheckedListBoxLibrary/SmartTextBox.cs | 80 ++++++++++ CheckedListBoxLibrary/SmartTextBox.resx | 120 +++++++++++++++ .../ValueOutOfRangeException.cs | 13 ++ .../testComponent.Designer.cs | 36 +++++ CheckedListBoxLibrary/testComponent.cs | 65 ++++++++ PIbd-33_Firsov_Kirill_KOP.sln | 31 ++++ WinFormsApp1/Form1.Designer.cs | 79 ++++++++++ WinFormsApp1/Form1.cs | 55 +++++++ WinFormsApp1/Form1.resx | 120 +++++++++++++++ WinFormsApp1/Form2.Designer.cs | 39 +++++ WinFormsApp1/Form2.cs | 20 +++ WinFormsApp1/Form2.resx | 120 +++++++++++++++ WinFormsApp1/Program.cs | 17 +++ WinFormsApp1/SampleClass.cs | 20 +++ WinFormsApp1/WinFormsApp1.csproj | 15 ++ WinFormsLibrary1/UserControl1.Designer.cs | 78 ++++++++++ WinFormsLibrary1/UserControl1.cs | 64 ++++++++ WinFormsLibrary1/UserControl1.resx | 123 +++++++++++++++ WinFormsLibrary1/WinFormsLibrary1.csproj | 10 ++ 28 files changed, 1798 insertions(+) create mode 100644 .gitattributes create mode 100644 CheckedListBoxLibrary/HierarchicalTreeView.Designer.cs create mode 100644 CheckedListBoxLibrary/HierarchicalTreeView.cs create mode 100644 CheckedListBoxLibrary/HierarchicalTreeView.resx create mode 100644 CheckedListBoxLibrary/MyUserControls.csproj create mode 100644 CheckedListBoxLibrary/SmartCheckedListBox.Designer.cs create mode 100644 CheckedListBoxLibrary/SmartCheckedListBox.cs create mode 100644 CheckedListBoxLibrary/SmartCheckedListBox.resx create mode 100644 CheckedListBoxLibrary/SmartTextBox.Designer.cs create mode 100644 CheckedListBoxLibrary/SmartTextBox.cs create mode 100644 CheckedListBoxLibrary/SmartTextBox.resx create mode 100644 CheckedListBoxLibrary/ValueOutOfRangeException.cs create mode 100644 CheckedListBoxLibrary/testComponent.Designer.cs create mode 100644 CheckedListBoxLibrary/testComponent.cs create mode 100644 PIbd-33_Firsov_Kirill_KOP.sln create mode 100644 WinFormsApp1/Form1.Designer.cs create mode 100644 WinFormsApp1/Form1.cs create mode 100644 WinFormsApp1/Form1.resx create mode 100644 WinFormsApp1/Form2.Designer.cs create mode 100644 WinFormsApp1/Form2.cs create mode 100644 WinFormsApp1/Form2.resx create mode 100644 WinFormsApp1/Program.cs create mode 100644 WinFormsApp1/SampleClass.cs create mode 100644 WinFormsApp1/WinFormsApp1.csproj create mode 100644 WinFormsLibrary1/UserControl1.Designer.cs create mode 100644 WinFormsLibrary1/UserControl1.cs create mode 100644 WinFormsLibrary1/UserControl1.resx create mode 100644 WinFormsLibrary1/WinFormsLibrary1.csproj diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/CheckedListBoxLibrary/HierarchicalTreeView.Designer.cs b/CheckedListBoxLibrary/HierarchicalTreeView.Designer.cs new file mode 100644 index 0000000..0a40b7e --- /dev/null +++ b/CheckedListBoxLibrary/HierarchicalTreeView.Designer.cs @@ -0,0 +1,55 @@ +namespace MyUserControls +{ + partial class HierarchicalTreeView + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + treeView = new TreeView(); + SuspendLayout(); + // + // treeView + // + treeView.Location = new Point(25, 26); + treeView.Name = "treeView"; + treeView.Size = new Size(213, 130); + treeView.TabIndex = 0; + // + // HierarchicalTreeView + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(treeView); + Name = "HierarchicalTreeView"; + Size = new Size(280, 180); + ResumeLayout(false); + } + + #endregion + + private TreeView treeView; + } +} diff --git a/CheckedListBoxLibrary/HierarchicalTreeView.cs b/CheckedListBoxLibrary/HierarchicalTreeView.cs new file mode 100644 index 0000000..ec6cb96 --- /dev/null +++ b/CheckedListBoxLibrary/HierarchicalTreeView.cs @@ -0,0 +1,143 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace MyUserControls +{ + public partial class HierarchicalTreeView : UserControl + { + private List propertyHierarchy = new List(); + public HierarchicalTreeView() + { + InitializeComponent(); + } + // Установка иерархии свойств + public void SetPropertyHierarchy(List propertyNames) + { + if (propertyNames == null) + { + throw new ArgumentNullException(nameof(propertyNames), "Объект не может быть null."); + } + + foreach (var name in propertyNames) + propertyHierarchy.Add(name); + } + + // Параметризованный метод для заполнения дерева + public void AddObject(T obj) + { + if (obj == null) + throw new ArgumentNullException(nameof(obj)); + + // Получаем значение первого свойства из иерархии + string initialValue = GetPropertyValue(obj, propertyHierarchy[0]); + TreeNode currentNode = FindOrCreateNode(treeView.Nodes, initialValue); + + // Обходим остальные свойства и строим ветвление + for (int i = 1; i < propertyHierarchy.Count; i++) + { + string nextProperty = propertyHierarchy[i]; + string nextValue = GetPropertyValue(obj, nextProperty); + + currentNode = FindOrCreateNode(currentNode.Nodes, nextValue); + } + } + + // Вспомогательный метод для получения значения свойства + private string GetPropertyValue(T obj, string propertyName) + { + // Используем рефлексию для получения значения свойства + PropertyInfo propertyInfo = typeof(T).GetProperty(propertyName); + if (propertyInfo == null) + throw new ArgumentException($"Свойство {propertyName} не найдено в классе {typeof(T).Name}."); + + object value = propertyInfo.GetValue(obj); + return value?.ToString() ?? "null"; // Возвращаем "null" вместо null + } + + // Вспомогательный метод для нахождения или создания узла + private TreeNode FindOrCreateNode(TreeNodeCollection nodes, string value) + { + foreach (TreeNode node in nodes) + { + if (node.Text.Equals(value, StringComparison.OrdinalIgnoreCase)) + { + return node; + } + } + TreeNode newNode = new TreeNode(value); + nodes.Add(newNode); + return newNode; + } + + public T? GetSelectedItem() where T : class, new() + { + if (treeView.SelectedNode == null) + { + throw new Exception("There are no selected nodes"); + } + if (treeView.SelectedNode.Nodes.Count != 0) + { + throw new Exception("Node is not the end node"); + } + + T result = new T(); + Type type = typeof(T); + TreeNode treeNode = treeView.SelectedNode; + + // Перебор узлов сверху вниз, начиная с выбранного узла + for (int i = propertyHierarchy.Count - 1; i >= 0 && treeNode != null; i--, treeNode = treeNode.Parent) + { + // Получаем свойство по названию из propertyHierarchy + var property = type.GetProperty(propertyHierarchy[i]); + if (property != null && property.CanWrite) + { + // Сеттим значение свойства из текста узла + property.SetValue(result, treeNode.Text); + } + } + + // Проверка на выполнение условий: если treeNode не null и i >= 0 (прекращаем заполнение) + if (treeNode != null || propertyHierarchy.Count > 0) + { + return result; + } + + return null; + } + + // Метод для выбора узла по его индексу + public void SelectNode(int index, string nodeNameToSelect) + { + // Получение узла по индексу + if (index >= 0 && index < treeView.Nodes.Count) + { + TreeNode currentNode = treeView.Nodes[1]; + + for (int i = propertyHierarchy.Count - 1; i >= 0 && currentNode != null; i--, currentNode = currentNode.FirstNode) + { + if (currentNode.FirstNode.Text == nodeNameToSelect) + { + treeView.SelectedNode = currentNode.FirstNode; + break; // Выход из цикла после выбора узла + } + } + + } + else + { + throw new ArgumentOutOfRangeException("Неверный индекс или имя узла"); + } + } + + + + } +} diff --git a/CheckedListBoxLibrary/HierarchicalTreeView.resx b/CheckedListBoxLibrary/HierarchicalTreeView.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CheckedListBoxLibrary/HierarchicalTreeView.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CheckedListBoxLibrary/MyUserControls.csproj b/CheckedListBoxLibrary/MyUserControls.csproj new file mode 100644 index 0000000..060aa1c --- /dev/null +++ b/CheckedListBoxLibrary/MyUserControls.csproj @@ -0,0 +1,10 @@ + + + + net6.0-windows + enable + true + enable + + + diff --git a/CheckedListBoxLibrary/SmartCheckedListBox.Designer.cs b/CheckedListBoxLibrary/SmartCheckedListBox.Designer.cs new file mode 100644 index 0000000..3ac673d --- /dev/null +++ b/CheckedListBoxLibrary/SmartCheckedListBox.Designer.cs @@ -0,0 +1,57 @@ +namespace MyUserControls +{ + partial class SmartCheckedListBox + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + checkedListBox = new CheckedListBox(); + SuspendLayout(); + // + // checkedListBox + // + checkedListBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + checkedListBox.FormattingEnabled = true; + checkedListBox.Location = new Point(14, 13); + checkedListBox.Name = "checkedListBox"; + checkedListBox.Size = new Size(322, 224); + checkedListBox.TabIndex = 2; + checkedListBox.SelectedIndexChanged += OnCheckedListBoxSelectedIndexChanged; + // + // SmartCheckedListBox + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(checkedListBox); + Name = "SmartCheckedListBox"; + Size = new Size(350, 264); + ResumeLayout(false); + } + + #endregion + private CheckedListBox checkedListBox; + } +} diff --git a/CheckedListBoxLibrary/SmartCheckedListBox.cs b/CheckedListBoxLibrary/SmartCheckedListBox.cs new file mode 100644 index 0000000..12e962c --- /dev/null +++ b/CheckedListBoxLibrary/SmartCheckedListBox.cs @@ -0,0 +1,68 @@ +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 MyUserControls +{ + public partial class SmartCheckedListBox : UserControl + { + public event EventHandler SelectionChanged; + + public SmartCheckedListBox() + { + InitializeComponent(); + } + + // Метод для добавления элемента в список + public void AddItem(string item) + { + if (!string.IsNullOrEmpty(item) && !checkedListBox.Items.Contains(item)) + { + checkedListBox.Items.Add(item); + } + } + + // Метод для очистки списка + public void ClearItems() + { + checkedListBox.Items.Clear(); + } + + // Публичное свойство для получения и установки выделенного значения + public string SelectedValue + { + get + { + if (checkedListBox.SelectedItem != null) + return checkedListBox.SelectedItem.ToString(); + return string.Empty; + } + set + { + for (int i = 0; i < checkedListBox.Items.Count; i++) + { + checkedListBox.SetItemChecked(i, false); + if (checkedListBox.Items[i].ToString() == value) + { + checkedListBox.SetItemChecked(i, true); + checkedListBox.SelectedIndex = i; + } + } + } + } + + // Метод, вызываемый при изменении выбора + protected virtual void OnCheckedListBoxSelectedIndexChanged(object sender, EventArgs e) + { + SelectionChanged?.Invoke(this, e); + SelectedValue = SelectedValue; + } + + } +} diff --git a/CheckedListBoxLibrary/SmartCheckedListBox.resx b/CheckedListBoxLibrary/SmartCheckedListBox.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CheckedListBoxLibrary/SmartCheckedListBox.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CheckedListBoxLibrary/SmartTextBox.Designer.cs b/CheckedListBoxLibrary/SmartTextBox.Designer.cs new file mode 100644 index 0000000..cb0f48e --- /dev/null +++ b/CheckedListBoxLibrary/SmartTextBox.Designer.cs @@ -0,0 +1,57 @@ +namespace MyUserControls +{ + partial class SmartTextBox + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + textBox1 = new TextBox(); + SuspendLayout(); + // + // textBox1 + // + textBox1.Location = new Point(18, 39); + textBox1.Name = "textBox1"; + textBox1.Size = new Size(268, 27); + textBox1.TabIndex = 0; + textBox1.TextChanged += TextBox1_TextChanged; + // + // SmartTextBox + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(textBox1); + Name = "SmartTextBox"; + Size = new Size(302, 177); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBox1; + } +} diff --git a/CheckedListBoxLibrary/SmartTextBox.cs b/CheckedListBoxLibrary/SmartTextBox.cs new file mode 100644 index 0000000..70fc48a --- /dev/null +++ b/CheckedListBoxLibrary/SmartTextBox.cs @@ -0,0 +1,80 @@ +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 MyUserControls +{ + public partial class SmartTextBox : UserControl + { + private int _minLength; + private int _maxLength; + private string _inputText; + + public int MinLength + { + get => _minLength; + set => _minLength = value; + } + + public int MaxLength + { + get => _maxLength; + set => _maxLength = value; + } + + public string InputText + { + get + { + if (MinLength == 0 && MaxLength == 0) + { + throw new ValueOutOfRangeException("Диапазон значений не задан."); + } + if (_inputText.Length < MinLength || _inputText.Length > MaxLength) + { + throw new ValueOutOfRangeException("Введенное значение не входит в диапазон."); + } + return _inputText; + } + set + { + if (MinLength > 0 || MaxLength > 0) + { + if (value.Length < MinLength || value.Length > MaxLength) + { + + return; + } + } + _inputText = value; + textBox1.Text = value; + OnInputTextChanged(EventArgs.Empty); + } + } + + public event EventHandler? InputTextChanged; + + public SmartTextBox() + { + InitializeComponent(); + textBox1.TextChanged += TextBox1_TextChanged; + } + + private void TextBox1_TextChanged(object sender, EventArgs e) + { + InputText = textBox1.Text; + } + + protected virtual void OnInputTextChanged(EventArgs e) + { + InputTextChanged?.Invoke(this, e); + } + } +} + diff --git a/CheckedListBoxLibrary/SmartTextBox.resx b/CheckedListBoxLibrary/SmartTextBox.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CheckedListBoxLibrary/SmartTextBox.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CheckedListBoxLibrary/ValueOutOfRangeException.cs b/CheckedListBoxLibrary/ValueOutOfRangeException.cs new file mode 100644 index 0000000..c40b9ab --- /dev/null +++ b/CheckedListBoxLibrary/ValueOutOfRangeException.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyUserControls +{ + public class ValueOutOfRangeException : Exception + { + public ValueOutOfRangeException(string message) : base(message) { } + } +} diff --git a/CheckedListBoxLibrary/testComponent.Designer.cs b/CheckedListBoxLibrary/testComponent.Designer.cs new file mode 100644 index 0000000..d8cf8c9 --- /dev/null +++ b/CheckedListBoxLibrary/testComponent.Designer.cs @@ -0,0 +1,36 @@ +namespace MyUserControls.Components +{ + partial class testComponent + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/CheckedListBoxLibrary/testComponent.cs b/CheckedListBoxLibrary/testComponent.cs new file mode 100644 index 0000000..b3965bc --- /dev/null +++ b/CheckedListBoxLibrary/testComponent.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyUserControls.Components +{ + public partial class testComponent : Component + { + public testComponent() + { + InitializeComponent(); + _fileName = string.Empty; + } + + public testComponent(IContainer container) + { + container.Add(this); + InitializeComponent(); + _fileName = string.Empty; + } + + private string _fileName; + public string FileName + { + set + { + if (string.IsNullOrEmpty(value)) + { + return; + } + if (!value.EndsWith(".txt")) + { + throw new ArgumentException("No txt file"); + } + _fileName = value; + } + } + public bool SaveToFile(string[] texts) + { + CheckFileExsists(); + using var writer = new StreamWriter(_fileName, true); + foreach (var text in texts) + { + writer.WriteLine(text); + } + writer.Flush(); + return true; + } + private void CheckFileExsists() + { + if (string.IsNullOrEmpty(_fileName)) + { + throw new ArgumentNullException(_fileName); + } + if (!File.Exists(_fileName)) + { + throw new FileNotFoundException(_fileName); + } + } + } +} diff --git a/PIbd-33_Firsov_Kirill_KOP.sln b/PIbd-33_Firsov_Kirill_KOP.sln new file mode 100644 index 0000000..8fe0937 --- /dev/null +++ b/PIbd-33_Firsov_Kirill_KOP.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34728.123 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsApp1", "WinFormsApp1\WinFormsApp1.csproj", "{704BA8ED-4148-4432-8485-B6ED6D47B303}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyUserControls", "CheckedListBoxLibrary\MyUserControls.csproj", "{0502BB43-17A6-420A-A9D5-5B88A5A54074}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {704BA8ED-4148-4432-8485-B6ED6D47B303}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {704BA8ED-4148-4432-8485-B6ED6D47B303}.Debug|Any CPU.Build.0 = Debug|Any CPU + {704BA8ED-4148-4432-8485-B6ED6D47B303}.Release|Any CPU.ActiveCfg = Release|Any CPU + {704BA8ED-4148-4432-8485-B6ED6D47B303}.Release|Any CPU.Build.0 = Release|Any CPU + {0502BB43-17A6-420A-A9D5-5B88A5A54074}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0502BB43-17A6-420A-A9D5-5B88A5A54074}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0502BB43-17A6-420A-A9D5-5B88A5A54074}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0502BB43-17A6-420A-A9D5-5B88A5A54074}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D83E3A76-1102-4CB1-B4E2-8E076E904085} + EndGlobalSection +EndGlobal diff --git a/WinFormsApp1/Form1.Designer.cs b/WinFormsApp1/Form1.Designer.cs new file mode 100644 index 0000000..cb546ba --- /dev/null +++ b/WinFormsApp1/Form1.Designer.cs @@ -0,0 +1,79 @@ +namespace WinFormsApp1 +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + smartCheckedListBox1 = new MyUserControls.SmartCheckedListBox(); + smartTextBox1 = new MyUserControls.SmartTextBox(); + hierarchicalTreeView = new MyUserControls.HierarchicalTreeView(); + SuspendLayout(); + // + // smartCheckedListBox1 + // + smartCheckedListBox1.Location = new Point(37, 12); + smartCheckedListBox1.Name = "smartCheckedListBox1"; + smartCheckedListBox1.SelectedValue = ""; + smartCheckedListBox1.Size = new Size(241, 182); + smartCheckedListBox1.TabIndex = 1; + // + // smartTextBox1 + // + smartTextBox1.Location = new Point(12, 318); + smartTextBox1.MaxLength = 100; + smartTextBox1.MinLength = 0; + smartTextBox1.Name = "smartTextBox1"; + smartTextBox1.Size = new Size(312, 98); + smartTextBox1.TabIndex = 2; + // + // hierarchicalTreeView + // + hierarchicalTreeView.Location = new Point(12, 163); + hierarchicalTreeView.Name = "hierarchicalTreeView"; + hierarchicalTreeView.Size = new Size(266, 174); + hierarchicalTreeView.TabIndex = 3; + // + // Form1 + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1120, 450); + Controls.Add(hierarchicalTreeView); + Controls.Add(smartTextBox1); + Controls.Add(smartCheckedListBox1); + Name = "Form1"; + Text = "Form1"; + ResumeLayout(false); + } + + #endregion + + private MyUserControls.SmartCheckedListBox smartCheckedListBox1; + private MyUserControls.SmartTextBox smartTextBox1; + private MyUserControls.HierarchicalTreeView hierarchicalTreeView; + } +} diff --git a/WinFormsApp1/Form1.cs b/WinFormsApp1/Form1.cs new file mode 100644 index 0000000..d17c169 --- /dev/null +++ b/WinFormsApp1/Form1.cs @@ -0,0 +1,55 @@ +using MyUserControls; + +namespace WinFormsApp1 +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + InitialChekedListBox(); + InitialSmartTextBox(); + InitialTree(); + } + + private void InitialChekedListBox() + { + + smartCheckedListBox1.AddItem(" 1"); + smartCheckedListBox1.AddItem(" 2"); + smartCheckedListBox1.AddItem(" 3"); + + smartCheckedListBox1.SelectedValue = " 3"; + } + + private void InitialSmartTextBox() + { + + smartTextBox1.MinLength = 0; + smartTextBox1.MaxLength = 1000; + smartTextBox1.InputText = "jjjjj"; + } + + private void InitialTree() + { + var obj1 = new SampleClass { Name = "Item1", Category = "Category1", SubCategory = "SubCategory1" }; + var obj2 = new SampleClass { Name = "Item2", Category = "Category1", SubCategory = "SubCategory2" }; + + List properties = new List + { + "Name", + "Category", + "SubCategory" + }; + + hierarchicalTreeView.SetPropertyHierarchy(properties); + + hierarchicalTreeView.AddObject(obj1); + hierarchicalTreeView.AddObject(obj2); + + hierarchicalTreeView.SelectNode(1, "SubCategory2"); + + smartTextBox1.InputText = hierarchicalTreeView.GetSelectedItem().ToString(); + } + } +} diff --git a/WinFormsApp1/Form1.resx b/WinFormsApp1/Form1.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/WinFormsApp1/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WinFormsApp1/Form2.Designer.cs b/WinFormsApp1/Form2.Designer.cs new file mode 100644 index 0000000..6aa68dc --- /dev/null +++ b/WinFormsApp1/Form2.Designer.cs @@ -0,0 +1,39 @@ +namespace WinFormsApp1 +{ + partial class Form2 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "Form2"; + } + + #endregion + } +} \ No newline at end of file diff --git a/WinFormsApp1/Form2.cs b/WinFormsApp1/Form2.cs new file mode 100644 index 0000000..2776bae --- /dev/null +++ b/WinFormsApp1/Form2.cs @@ -0,0 +1,20 @@ +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 WinFormsApp1 +{ + public partial class Form2 : Form + { + public Form2() + { + InitializeComponent(); + } + } +} diff --git a/WinFormsApp1/Form2.resx b/WinFormsApp1/Form2.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/WinFormsApp1/Form2.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WinFormsApp1/Program.cs b/WinFormsApp1/Program.cs new file mode 100644 index 0000000..1e39c2a --- /dev/null +++ b/WinFormsApp1/Program.cs @@ -0,0 +1,17 @@ +namespace WinFormsApp1 +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file diff --git a/WinFormsApp1/SampleClass.cs b/WinFormsApp1/SampleClass.cs new file mode 100644 index 0000000..e5b18e2 --- /dev/null +++ b/WinFormsApp1/SampleClass.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinFormsApp1 +{ + public class SampleClass + { + public string Name { get; set; } + public string Category { get; set; } + public string SubCategory { get; set; } + + public override string ToString() + { + return Name + " " + Category + " " + SubCategory; + } + } +} diff --git a/WinFormsApp1/WinFormsApp1.csproj b/WinFormsApp1/WinFormsApp1.csproj new file mode 100644 index 0000000..f3803f8 --- /dev/null +++ b/WinFormsApp1/WinFormsApp1.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net6.0-windows7.0 + enable + true + enable + + + + + + + \ No newline at end of file diff --git a/WinFormsLibrary1/UserControl1.Designer.cs b/WinFormsLibrary1/UserControl1.Designer.cs new file mode 100644 index 0000000..0407ba0 --- /dev/null +++ b/WinFormsLibrary1/UserControl1.Designer.cs @@ -0,0 +1,78 @@ +namespace WinFormsLibrary1 +{ + partial class UserControl1 + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + pictureBoxAvatar = new PictureBox(); + button1 = new Button(); + backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); + ((System.ComponentModel.ISupportInitialize)pictureBoxAvatar).BeginInit(); + SuspendLayout(); + // + // pictureBoxAvatar + // + pictureBoxAvatar.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + pictureBoxAvatar.Location = new Point(6, 3); + pictureBoxAvatar.Name = "pictureBoxAvatar"; + pictureBoxAvatar.Size = new Size(330, 306); + pictureBoxAvatar.SizeMode = PictureBoxSizeMode.AutoSize; + pictureBoxAvatar.TabIndex = 0; + pictureBoxAvatar.TabStop = false; + pictureBoxAvatar.Click += ButtonLoad_Click; + // + // button1 + // + button1.Dock = DockStyle.Bottom; + button1.Location = new Point(0, 311); + button1.Name = "button1"; + button1.Size = new Size(339, 30); + button1.TabIndex = 1; + button1.Text = "button1"; + button1.UseVisualStyleBackColor = true; + button1.Click += ButtonLoad_Click; + // + // UserControl1 + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(button1); + Controls.Add(pictureBoxAvatar); + Name = "UserControl1"; + Size = new Size(339, 341); + ((System.ComponentModel.ISupportInitialize)pictureBoxAvatar).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private PictureBox pictureBoxAvatar; + private Button button1; + private System.ComponentModel.BackgroundWorker backgroundWorker1; + } +} diff --git a/WinFormsLibrary1/UserControl1.cs b/WinFormsLibrary1/UserControl1.cs new file mode 100644 index 0000000..785ac48 --- /dev/null +++ b/WinFormsLibrary1/UserControl1.cs @@ -0,0 +1,64 @@ +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 WinFormsLibrary1 +{ + public partial class UserControl1 : UserControl + { + private event EventHandler? _avatarChanged; + private event Action? _errorOccured; + public string Error { get; private set; } + public Image Avatar + { + get + { + return pictureBoxAvatar.Image; + } + set + { + pictureBoxAvatar.Image = value; + } + } + public event EventHandler AvatarChanged + { + add { _avatarChanged += value; } + remove { _avatarChanged -= value; } + } + public event Action AnErrorOccurred + { + add { _errorOccured += value; } + remove { _errorOccured -= value; } + } + public UserControl1() + { + InitializeComponent(); + Error = string.Empty; + } + private void ButtonLoad_Click(object sender, EventArgs e) + { + var ofd = new OpenFileDialog(); + if (ofd.ShowDialog() == DialogResult.OK) + { + try + { + pictureBoxAvatar.Image = + Image.FromFile(ofd.FileName); + _avatarChanged?.Invoke(this, e); + } + catch (Exception ex) + { + Error = ex.Message; + _errorOccured?.Invoke(); + } + } + } + } + +} diff --git a/WinFormsLibrary1/UserControl1.resx b/WinFormsLibrary1/UserControl1.resx new file mode 100644 index 0000000..fa7aa79 --- /dev/null +++ b/WinFormsLibrary1/UserControl1.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/WinFormsLibrary1/WinFormsLibrary1.csproj b/WinFormsLibrary1/WinFormsLibrary1.csproj new file mode 100644 index 0000000..060aa1c --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary1.csproj @@ -0,0 +1,10 @@ + + + + net6.0-windows + enable + true + enable + + +