From 2672be8d1b78fbe54c4494dac651a6501b51102d Mon Sep 17 00:00:00 2001 From: "annalyovushkina@yandex.ru" Date: Sun, 15 Sep 2024 03:28:24 +0400 Subject: [PATCH] =?UTF-8?q?=D1=83=D0=B6=D0=B5=20=D0=BF=D0=BE=D1=87=D1=82?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KOP_Labs/KOP_Labs.sln | 8 +- KOP_Labs/KOP_Labs/CustomComboBox.Designer.cs | 4 +- KOP_Labs/KOP_Labs/CustomComboBox.cs | 56 ++++-- KOP_Labs/KOP_Labs/CustomListBox.Designer.cs | 6 +- KOP_Labs/KOP_Labs/CustomListBox.cs | 9 +- KOP_Labs/KOP_Labs/CustomTree.Designer.cs | 4 +- KOP_Labs/KOP_Labs/CustomTree.cs | 98 ++++++++++- .../Exceptions/HierarcyNullException.cs | 20 +++ .../KOP_Labs/Exceptions/NoBordersException.cs | 15 ++ .../Exceptions/NoBordersExceptioncs.cs | 14 -- .../Exceptions/PropertyNullException.cs | 20 +++ .../KOP_Labs/Helpers/AlwaysCreateAttribute.cs | 13 ++ KOP_Labs/WinFormForTest/Form1.Designer.cs | 159 ++++++++++++++++++ KOP_Labs/WinFormForTest/Form1.cs | 76 +++++++++ KOP_Labs/WinFormForTest/Form1.resx | 120 +++++++++++++ KOP_Labs/WinFormForTest/Program.cs | 17 ++ KOP_Labs/WinFormForTest/TestClasses/Plant.cs | 24 +++ KOP_Labs/WinFormForTest/WinFormForTest.csproj | 15 ++ 18 files changed, 639 insertions(+), 39 deletions(-) create mode 100644 KOP_Labs/KOP_Labs/Exceptions/HierarcyNullException.cs create mode 100644 KOP_Labs/KOP_Labs/Exceptions/NoBordersException.cs delete mode 100644 KOP_Labs/KOP_Labs/Exceptions/NoBordersExceptioncs.cs create mode 100644 KOP_Labs/KOP_Labs/Exceptions/PropertyNullException.cs create mode 100644 KOP_Labs/KOP_Labs/Helpers/AlwaysCreateAttribute.cs create mode 100644 KOP_Labs/WinFormForTest/Form1.Designer.cs create mode 100644 KOP_Labs/WinFormForTest/Form1.cs create mode 100644 KOP_Labs/WinFormForTest/Form1.resx create mode 100644 KOP_Labs/WinFormForTest/Program.cs create mode 100644 KOP_Labs/WinFormForTest/TestClasses/Plant.cs create mode 100644 KOP_Labs/WinFormForTest/WinFormForTest.csproj diff --git a/KOP_Labs/KOP_Labs.sln b/KOP_Labs/KOP_Labs.sln index d516f77..ef85c2a 100644 --- a/KOP_Labs/KOP_Labs.sln +++ b/KOP_Labs/KOP_Labs.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.11.35208.52 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomComponents", "KOP_Labs\CustomComponents.csproj", "{30670FC3-546A-4837-8A6C-48D6A479F5CA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomComponents", "KOP_Labs\CustomComponents.csproj", "{30670FC3-546A-4837-8A6C-48D6A479F5CA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormForTest", "WinFormForTest\WinFormForTest.csproj", "{8C3EF3FC-79ED-4F01-A28D-7BD19DE978A5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {30670FC3-546A-4837-8A6C-48D6A479F5CA}.Debug|Any CPU.Build.0 = Debug|Any CPU {30670FC3-546A-4837-8A6C-48D6A479F5CA}.Release|Any CPU.ActiveCfg = Release|Any CPU {30670FC3-546A-4837-8A6C-48D6A479F5CA}.Release|Any CPU.Build.0 = Release|Any CPU + {8C3EF3FC-79ED-4F01-A28D-7BD19DE978A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8C3EF3FC-79ED-4F01-A28D-7BD19DE978A5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8C3EF3FC-79ED-4F01-A28D-7BD19DE978A5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8C3EF3FC-79ED-4F01-A28D-7BD19DE978A5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/KOP_Labs/KOP_Labs/CustomComboBox.Designer.cs b/KOP_Labs/KOP_Labs/CustomComboBox.Designer.cs index 8554466..9bf4df0 100644 --- a/KOP_Labs/KOP_Labs/CustomComboBox.Designer.cs +++ b/KOP_Labs/KOP_Labs/CustomComboBox.Designer.cs @@ -35,7 +35,7 @@ // textBox.Location = new Point(13, 55); textBox.Name = "textBox"; - textBox.Size = new Size(289, 27); + textBox.Size = new Size(263, 27); textBox.TabIndex = 0; textBox.TextChanged += textBox_TextChanged; textBox.Enter += textBox_Enter; @@ -46,7 +46,7 @@ AutoScaleMode = AutoScaleMode.Font; Controls.Add(textBox); Name = "CustomComboBox"; - Size = new Size(321, 183); + Size = new Size(289, 136); ResumeLayout(false); PerformLayout(); } diff --git a/KOP_Labs/KOP_Labs/CustomComboBox.cs b/KOP_Labs/KOP_Labs/CustomComboBox.cs index 244b9f2..2c1d982 100644 --- a/KOP_Labs/KOP_Labs/CustomComboBox.cs +++ b/KOP_Labs/KOP_Labs/CustomComboBox.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using CustomComponents.Exceptions; namespace KOP_Labs { @@ -17,9 +18,37 @@ namespace KOP_Labs InitializeComponent(); } private string examp = "Введите текст от " + decimal.MinValue + " до" + decimal.MaxValue + " символов"; - public string Error { get; protected set; } = string.Empty; - public decimal? MinValue { get; set; } - public decimal? MaxValue { get; set; } + + public int? max = null; + public int? min = null; + public int? Max + { + get + { + return max; + } + set + { + if (value == null || value <= 0) return; + max = value; + + } + + } + public int? Min + { + get + { + return min; + } + set + { + if (value == null || value < 0) return; + min = value; + + } + + } private EventHandler _changeEvent; public event EventHandler ChangeEvent @@ -49,28 +78,27 @@ namespace KOP_Labs { get { - if (MinValue == null || MaxValue == null) + if (Min == null || Max == null) { - Error = "Диапазон не задан"; - return null; + throw new NoBordersException("Границы не заданы"); } - if (textBox.Text.Length >= MinValue && textBox.Text.Length <= MaxValue) + if (textBox.Text.Length < Min || textBox.Text.Length > Max) { - return textBox.Text; + throw new ArgumentOutOfRangeException("Ваша строка не входит в границы диапозона: " + Min + " - " + Max); } - Error = "Ваш текст" + " лежит \n вне диапозона" + MinValue + " - " + MaxValue; - return null; + return textBox.Text; } set { - if (MinValue == null || MaxValue == null) + if (value == null || value.Length < 0 || Max == null) { - Error = "Диапазон не задан"; + return; } - if (value.Length >= MinValue && value.Length <= MaxValue) + if (value.Length < Min && value.Length > Max) { - textBox.Text = value; + return; } + textBox.Text = value; } } diff --git a/KOP_Labs/KOP_Labs/CustomListBox.Designer.cs b/KOP_Labs/KOP_Labs/CustomListBox.Designer.cs index 15b6e49..7442399 100644 --- a/KOP_Labs/KOP_Labs/CustomListBox.Designer.cs +++ b/KOP_Labs/KOP_Labs/CustomListBox.Designer.cs @@ -36,9 +36,9 @@ checkedListBox.FormattingEnabled = true; checkedListBox.Location = new Point(3, 16); checkedListBox.Name = "checkedListBox"; - checkedListBox.Size = new Size(214, 180); + checkedListBox.Size = new Size(197, 136); checkedListBox.TabIndex = 0; - checkedListBox.SelectedIndexChanged += this.checkedListBox_SelectedIndexChanged; + checkedListBox.SelectedIndexChanged += checkedListBox_SelectedIndexChanged; // // CustomListBox // @@ -46,7 +46,7 @@ AutoScaleMode = AutoScaleMode.Font; Controls.Add(checkedListBox); Name = "CustomListBox"; - Size = new Size(220, 223); + Size = new Size(220, 184); ResumeLayout(false); } diff --git a/KOP_Labs/KOP_Labs/CustomListBox.cs b/KOP_Labs/KOP_Labs/CustomListBox.cs index 781ed6c..f95dd2c 100644 --- a/KOP_Labs/KOP_Labs/CustomListBox.cs +++ b/KOP_Labs/KOP_Labs/CustomListBox.cs @@ -73,9 +73,14 @@ namespace KOP_Labs } set { - if (checkedListBox.Items.Contains(value)) { - checkedListBox.SelectedItem = value; + int index = checkedListBox.Items.IndexOf(value); + if (index == -1) + { + return; } + checkedListBox.SelectedItem = value; + checkedListBox.SetItemChecked(index, true); + } } } diff --git a/KOP_Labs/KOP_Labs/CustomTree.Designer.cs b/KOP_Labs/KOP_Labs/CustomTree.Designer.cs index 0218d57..c6679a9 100644 --- a/KOP_Labs/KOP_Labs/CustomTree.Designer.cs +++ b/KOP_Labs/KOP_Labs/CustomTree.Designer.cs @@ -35,7 +35,7 @@ // treeView.Location = new Point(3, 3); treeView.Name = "treeView"; - treeView.Size = new Size(360, 425); + treeView.Size = new Size(291, 358); treeView.TabIndex = 0; // // CustomTree @@ -44,7 +44,7 @@ AutoScaleMode = AutoScaleMode.Font; Controls.Add(treeView); Name = "CustomTree"; - Size = new Size(366, 431); + Size = new Size(307, 364); ResumeLayout(false); } diff --git a/KOP_Labs/KOP_Labs/CustomTree.cs b/KOP_Labs/KOP_Labs/CustomTree.cs index f2f6a7e..458271a 100644 --- a/KOP_Labs/KOP_Labs/CustomTree.cs +++ b/KOP_Labs/KOP_Labs/CustomTree.cs @@ -1,9 +1,12 @@ -using System; +using CustomComponents.Exceptions; +using CustomComponents.Helpers; +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; @@ -17,10 +20,103 @@ namespace KOP_Labs InitializeComponent(); } + public List? Hierarcy { get; set; } public void Clear() { treeView.Nodes.Clear(); } + public void AddNode(T obj) { + if (Hierarcy == null) + { + throw new HierarcyNullException("Иерархия не задана"); + } + if (obj == null) + { + throw new ArgumentNullException("Объект не найден"); + } + var values = GetValuesVithStructure(obj); + var treeNode = new TreeNode(); + AddNodesToTreeNode(treeView.Nodes, treeNode.Nodes); + var nodes = AddElementsToParent(values, treeNode); + treeView.Nodes.Clear(); + AddNodesToTreeNode(nodes.Nodes, treeView.Nodes); + } + private void AddNodesToTreeNode(TreeNodeCollection fromNodeCollection, TreeNodeCollection toNodeCollection) + { + for (int i = 0; i < fromNodeCollection.Count; i++) + { + var node = fromNodeCollection[i].Clone() as TreeNode; + toNodeCollection.Add(node); + } + } + private Dictionary GetValuesVithStructure(T obj) + { + PropertyInfo[]? properties = obj?.GetType().GetProperties(); + var dict = new Dictionary(); + foreach (var elem in Hierarcy!) { + PropertyInfo? prop = properties?.Single(prop => prop.Name == elem); + if (prop == null) + { + throw new PropertyNullException(nameof(prop)); + } + var atr = prop.GetCustomAttributes()?.SingleOrDefault(atr => atr is AlwaysCreateAttribute); + dict[elem] = (prop.GetValue(obj)!, atr == null ? false : true); + } + return dict; + } + private TreeNode AddElementsToParent(Dictionary elements, TreeNode parent) + { + if (elements.Count == 0) + { + return parent; + } + var firstElem = elements.First(); + var child = parent.Nodes + .Cast() + .SingleOrDefault(node => node.Text == (string)firstElem.Value.Item1); + + if (child != null && !firstElem.Value.Item2) + { + elements.Remove(firstElem.Key); + return AddElementsToParent(elements, child).Parent; + } + else + { + var newChild = new TreeNode(firstElem.Value.Item1?.ToString() ?? string.Empty); + + newChild.Tag = new Tuple(firstElem.Key, firstElem.Value.Item1!); + + elements.Remove(firstElem.Key); + parent.Nodes.Add(AddElementsToParent(elements, newChild)); + return parent; + } + } + public T GetSelectedNode() + where T : new() + { + if (Hierarcy == null) + { + throw new HierarcyNullException("Иерархия не задана"); + } + if (treeView.SelectedNode == null) + { + return new T(); + } + return GetNode(new T(), treeView.SelectedNode); + } + private T GetNode(T obj, TreeNode node) + { + if (node != null && node.Tag != null) + { + var tag = node.Tag as Tuple; + + var property = obj?.GetType().GetProperty(tag!.Item1); + property?.SetValue(obj, Convert.ChangeType(tag!.Item2, property.PropertyType)); + + GetNode(obj, node.Parent); + } + return obj; + } } } diff --git a/KOP_Labs/KOP_Labs/Exceptions/HierarcyNullException.cs b/KOP_Labs/KOP_Labs/Exceptions/HierarcyNullException.cs new file mode 100644 index 0000000..8560b6f --- /dev/null +++ b/KOP_Labs/KOP_Labs/Exceptions/HierarcyNullException.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CustomComponents.Exceptions +{ + public class HierarcyNullException : Exception + { + public HierarcyNullException() { } + public HierarcyNullException(string message) : base(message) + { + } + + public HierarcyNullException(string message, Exception inner) : base(message, inner) + { + } + } +} diff --git a/KOP_Labs/KOP_Labs/Exceptions/NoBordersException.cs b/KOP_Labs/KOP_Labs/Exceptions/NoBordersException.cs new file mode 100644 index 0000000..6de0ddc --- /dev/null +++ b/KOP_Labs/KOP_Labs/Exceptions/NoBordersException.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CustomComponents.Exceptions +{ + public class NoBordersException : Exception + { + public NoBordersException() { } + public NoBordersException(string message) : base(message){ } + public NoBordersException(string message, Exception inner) : base(message, inner) { } + } +} diff --git a/KOP_Labs/KOP_Labs/Exceptions/NoBordersExceptioncs.cs b/KOP_Labs/KOP_Labs/Exceptions/NoBordersExceptioncs.cs deleted file mode 100644 index b6fecec..0000000 --- a/KOP_Labs/KOP_Labs/Exceptions/NoBordersExceptioncs.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CustomComponents.Exceptions -{ - public class NoBordersExceptioncs - { - public NoBordersExceptioncs() { } - public NoBordersExceptioncs(string message) : base(message){ } - } -} diff --git a/KOP_Labs/KOP_Labs/Exceptions/PropertyNullException.cs b/KOP_Labs/KOP_Labs/Exceptions/PropertyNullException.cs new file mode 100644 index 0000000..eea0aed --- /dev/null +++ b/KOP_Labs/KOP_Labs/Exceptions/PropertyNullException.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CustomComponents.Exceptions +{ + public class PropertyNullException : Exception + { + public PropertyNullException() { } + public PropertyNullException(string message) : base(message) + { + } + + public PropertyNullException(string message, Exception inner) : base(message, inner) + { + } + } +} diff --git a/KOP_Labs/KOP_Labs/Helpers/AlwaysCreateAttribute.cs b/KOP_Labs/KOP_Labs/Helpers/AlwaysCreateAttribute.cs new file mode 100644 index 0000000..c2b0143 --- /dev/null +++ b/KOP_Labs/KOP_Labs/Helpers/AlwaysCreateAttribute.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CustomComponents.Helpers +{ + public class AlwaysCreateAttribute : Attribute + { + public AlwaysCreateAttribute() { } + } +} diff --git a/KOP_Labs/WinFormForTest/Form1.Designer.cs b/KOP_Labs/WinFormForTest/Form1.Designer.cs new file mode 100644 index 0000000..ad8b7ff --- /dev/null +++ b/KOP_Labs/WinFormForTest/Form1.Designer.cs @@ -0,0 +1,159 @@ +namespace WinFormForTest +{ + 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() + { + customComboBox1 = new KOP_Labs.CustomComboBox(); + customListBox1 = new KOP_Labs.CustomListBox(); + customTree1 = new KOP_Labs.CustomTree(); + buttonClear = new Button(); + buttonEnter = new Button(); + buttonGet = new Button(); + labelItem = new Label(); + buttonCheck = new Button(); + checkBoxValid = new CheckBox(); + SuspendLayout(); + // + // customComboBox1 + // + customComboBox1.Location = new Point(264, 50); + customComboBox1.Max = 20; + customComboBox1.Min = 5; + customComboBox1.Name = "customComboBox1"; + customComboBox1.Size = new Size(301, 125); + customComboBox1.TabIndex = 0; + customComboBox1.TextBoxValue = ""; + // + // customListBox1 + // + customListBox1.Location = new Point(12, 23); + customListBox1.Name = "customListBox1"; + customListBox1.SelectedElement = ""; + customListBox1.Size = new Size(231, 187); + customListBox1.TabIndex = 1; + // + // customTree1 + // + customTree1.Hierarcy = null; + customTree1.Location = new Point(615, 50); + customTree1.Name = "customTree1"; + customTree1.Size = new Size(309, 384); + customTree1.TabIndex = 2; + // + // buttonClear + // + buttonClear.Location = new Point(12, 216); + buttonClear.Name = "buttonClear"; + buttonClear.Size = new Size(161, 29); + buttonClear.TabIndex = 3; + buttonClear.Text = "Очистить список"; + buttonClear.UseVisualStyleBackColor = true; + buttonClear.Click += buttonClear_Click; + // + // buttonEnter + // + buttonEnter.Location = new Point(12, 251); + buttonEnter.Name = "buttonEnter"; + buttonEnter.Size = new Size(183, 29); + buttonEnter.TabIndex = 4; + buttonEnter.Text = "Добавить элементы"; + buttonEnter.UseVisualStyleBackColor = true; + buttonEnter.Click += buttonEnter_Click; + // + // buttonGet + // + buttonGet.Location = new Point(12, 286); + buttonGet.Name = "buttonGet"; + buttonGet.Size = new Size(94, 29); + buttonGet.TabIndex = 5; + buttonGet.Text = "Получить"; + buttonGet.UseVisualStyleBackColor = true; + buttonGet.Click += buttonGet_Click; + // + // labelItem + // + labelItem.AutoSize = true; + labelItem.Location = new Point(123, 290); + labelItem.Name = "labelItem"; + labelItem.Size = new Size(59, 20); + labelItem.TabIndex = 6; + labelItem.Text = "Объект"; + // + // buttonCheck + // + buttonCheck.Location = new Point(273, 181); + buttonCheck.Name = "buttonCheck"; + buttonCheck.Size = new Size(94, 29); + buttonCheck.TabIndex = 7; + buttonCheck.Text = "Проверить"; + buttonCheck.UseVisualStyleBackColor = true; + buttonCheck.Click += buttonCheck_Click; + // + // checkBoxValid + // + checkBoxValid.AutoSize = true; + checkBoxValid.Location = new Point(417, 181); + checkBoxValid.Name = "checkBoxValid"; + checkBoxValid.Size = new Size(100, 24); + checkBoxValid.TabIndex = 9; + checkBoxValid.Text = "Проверка"; + checkBoxValid.UseVisualStyleBackColor = true; + // + // Form1 + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1042, 573); + Controls.Add(checkBoxValid); + Controls.Add(buttonCheck); + Controls.Add(labelItem); + Controls.Add(buttonGet); + Controls.Add(buttonEnter); + Controls.Add(buttonClear); + Controls.Add(customTree1); + Controls.Add(customListBox1); + Controls.Add(customComboBox1); + Name = "Form1"; + Text = "Form1"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private KOP_Labs.CustomComboBox customComboBox1; + private KOP_Labs.CustomListBox customListBox1; + private KOP_Labs.CustomTree customTree1; + private Button buttonClear; + private Button buttonEnter; + private Button buttonGet; + private Label labelItem; + private Button buttonCheck; + private CheckBox checkBoxValid; + } +} diff --git a/KOP_Labs/WinFormForTest/Form1.cs b/KOP_Labs/WinFormForTest/Form1.cs new file mode 100644 index 0000000..beec2f0 --- /dev/null +++ b/KOP_Labs/WinFormForTest/Form1.cs @@ -0,0 +1,76 @@ +using WinFormForTest.TestClasses; + +namespace WinFormForTest +{ + public partial class Form1 : Form + { + List plants = new List(); + public Form1() + { + InitializeComponent(); + customListBox1.AddToList(" 1"); + customListBox1.AddToList(" 2"); + customListBox1.AddToList(" 3"); + Plant pl1 = new Plant("", "", ""); + Plant pl2 = new Plant("", "", ""); + Plant pl3 = new Plant("", "", ""); + Plant pl4 = new Plant("", "", ""); + Plant pl5 = new Plant("", "", ""); + Plant pl6 = new Plant("", "", ""); + plants.Add(pl1); + plants.Add(pl4); + plants.Add(pl2); + plants.Add(pl5); + plants.Add(pl3); + plants.Add(pl6); + LoadTree(); + } + + public void LoadTree() + { + customTree1.Hierarcy = new List { "Color", "Name", "Type" }; + foreach (Plant plant in plants) + { + customTree1.AddNode(plant); + } + } + private void buttonClear_Click(object sender, EventArgs e) + { + customListBox1.Clear(); + } + + private void buttonCheck_Click(object sender, EventArgs e) + { + try + { + + if (customComboBox1.TextBoxValue != null) + { + checkBoxValid.Text = ""; + checkBoxValid.Checked = true; + checkBoxValid.BackColor = Color.Green; + } + } + catch (Exception ex) + { + checkBoxValid.Text = " "; + checkBoxValid.Checked = false; + checkBoxValid.BackColor = Color.Red; + MessageBox.Show(ex.Message); + } + } + + private void buttonEnter_Click(object sender, EventArgs e) + { + customListBox1.AddToList(" 4"); + customListBox1.AddToList(" 5"); + customListBox1.AddToList(" 6"); + } + + private void buttonGet_Click(object sender, EventArgs e) + { + labelItem.Text = customListBox1.SelectedElement; + } + + } +} diff --git a/KOP_Labs/WinFormForTest/Form1.resx b/KOP_Labs/WinFormForTest/Form1.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/KOP_Labs/WinFormForTest/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/KOP_Labs/WinFormForTest/Program.cs b/KOP_Labs/WinFormForTest/Program.cs new file mode 100644 index 0000000..1ab60a9 --- /dev/null +++ b/KOP_Labs/WinFormForTest/Program.cs @@ -0,0 +1,17 @@ +namespace WinFormForTest +{ + 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/KOP_Labs/WinFormForTest/TestClasses/Plant.cs b/KOP_Labs/WinFormForTest/TestClasses/Plant.cs new file mode 100644 index 0000000..26a7064 --- /dev/null +++ b/KOP_Labs/WinFormForTest/TestClasses/Plant.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CustomComponents.Helpers; + +namespace WinFormForTest.TestClasses +{ + public class Plant + { + [AlwaysCreate] + public string Type { get; set; } + public string Name { get; set; } + public string Color { get; set; } + public Plant(string type, string name, string color) + { + Type = type; + Name = name; + Color = color; + } + public Plant() { } + } +} diff --git a/KOP_Labs/WinFormForTest/WinFormForTest.csproj b/KOP_Labs/WinFormForTest/WinFormForTest.csproj new file mode 100644 index 0000000..3e51e6c --- /dev/null +++ b/KOP_Labs/WinFormForTest/WinFormForTest.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + \ No newline at end of file