From 1d7d23e749bb63dc387b9d585c0b47cd2cd4e8f4 Mon Sep 17 00:00:00 2001 From: Factorino73 Date: Thu, 5 Sep 2024 18:58:41 +0400 Subject: [PATCH] LabWork01 --- .../CustomComboBox.Designer.cs | 72 ++++++ .../VisualComponents/CustomComboBox.cs | 107 ++++++++ .../VisualComponents/CustomComboBox.resx | 120 +++++++++ .../CustomListBox.Designer.cs | 58 +++++ .../VisualComponents/CustomListBox.cs | 162 +++++++++++++ .../VisualComponents/CustomListBox.resx | 120 +++++++++ .../CustomTextBox.Designer.cs | 71 ++++++ .../VisualComponents/CustomTextBox.cs | 146 +++++++++++ .../VisualComponents/CustomTextBox.resx | 120 +++++++++ .../Exceptions/InvalidInputException.cs | 25 ++ .../Exceptions/NullPatternException.cs | 25 ++ .../WinForms/FormComponents.Designer.cs | 229 +++++++++++++++++- Components/WinForms/FormComponents.cs | 124 ++++++++++ Components/WinForms/Person.cs | 40 +++ Components/WinForms/WinForms.csproj | 4 + 15 files changed, 1422 insertions(+), 1 deletion(-) create mode 100644 Components/Components/VisualComponents/CustomComboBox.Designer.cs create mode 100644 Components/Components/VisualComponents/CustomComboBox.cs create mode 100644 Components/Components/VisualComponents/CustomComboBox.resx create mode 100644 Components/Components/VisualComponents/CustomListBox.Designer.cs create mode 100644 Components/Components/VisualComponents/CustomListBox.cs create mode 100644 Components/Components/VisualComponents/CustomListBox.resx create mode 100644 Components/Components/VisualComponents/CustomTextBox.Designer.cs create mode 100644 Components/Components/VisualComponents/CustomTextBox.cs create mode 100644 Components/Components/VisualComponents/CustomTextBox.resx create mode 100644 Components/Components/VisualComponents/Exceptions/InvalidInputException.cs create mode 100644 Components/Components/VisualComponents/Exceptions/NullPatternException.cs create mode 100644 Components/WinForms/Person.cs diff --git a/Components/Components/VisualComponents/CustomComboBox.Designer.cs b/Components/Components/VisualComponents/CustomComboBox.Designer.cs new file mode 100644 index 0000000..8b8b504 --- /dev/null +++ b/Components/Components/VisualComponents/CustomComboBox.Designer.cs @@ -0,0 +1,72 @@ +namespace Components.VisualComponents +{ + partial class CustomComboBox + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + comboBox = new ComboBox(); + labelComboBox = new Label(); + SuspendLayout(); + // + // comboBox + // + comboBox.Dock = DockStyle.Bottom; + comboBox.DropDownStyle = ComboBoxStyle.DropDownList; + comboBox.FormattingEnabled = true; + comboBox.Location = new Point(0, 30); + comboBox.Name = "comboBox"; + comboBox.Size = new Size(170, 23); + comboBox.TabIndex = 0; + comboBox.SelectedValueChanged += comboBox_SelectedValueChanged; + // + // labelComboBox + // + labelComboBox.AutoSize = true; + labelComboBox.Location = new Point(10, 10); + labelComboBox.Name = "labelComboBox"; + labelComboBox.Size = new Size(125, 15); + labelComboBox.TabIndex = 1; + labelComboBox.Text = "Выпадающий список"; + // + // CustomComboBox + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(labelComboBox); + Controls.Add(comboBox); + Name = "CustomComboBox"; + Size = new Size(170, 53); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBox; + private Label labelComboBox; + } +} diff --git a/Components/Components/VisualComponents/CustomComboBox.cs b/Components/Components/VisualComponents/CustomComboBox.cs new file mode 100644 index 0000000..86b0670 --- /dev/null +++ b/Components/Components/VisualComponents/CustomComboBox.cs @@ -0,0 +1,107 @@ +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 Components.VisualComponents +{ + /// + /// Визуальный компонент для выбора из выпадающего списка + /// + public partial class CustomComboBox : UserControl + { + /// + /// Событие, вызываемое при смене значения + /// + private EventHandler _onValueChangedEvent; + + /// + /// Событие, вызываемое при смене значения + /// + public event EventHandler ValueChanged + { + add + { + _onValueChangedEvent += value; + } + + remove + { + _onValueChangedEvent -= value; + } + } + + /// + /// Выбранный элемент + /// + public string SelectedItem + { + get + { + if (comboBox.Items.Count == 0) + { + return ""; + } + if (comboBox.SelectedItem == null) + { + return ""; + } + + return comboBox.SelectedItem.ToString()!; + } + + set + { + if (comboBox.Items.Contains(value)) + { + comboBox.SelectedItem = value; + } + } + } + + /// + /// Конструктор + /// + public CustomComboBox() + { + InitializeComponent(); + } + + /// + /// Добавить элемент + /// + /// + public void AddItem(string item) + { + if (item == null) + { + return; + } + + comboBox.Items.Add(item); + } + + /// + /// Очистить список + /// + public void Clear() + { + comboBox.Items.Clear(); + } + + /// + /// Смена значения + /// + /// + /// + private void comboBox_SelectedValueChanged(object sender, EventArgs e) + { + _onValueChangedEvent?.Invoke(sender, e); + } + } +} diff --git a/Components/Components/VisualComponents/CustomComboBox.resx b/Components/Components/VisualComponents/CustomComboBox.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Components/Components/VisualComponents/CustomComboBox.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/Components/Components/VisualComponents/CustomListBox.Designer.cs b/Components/Components/VisualComponents/CustomListBox.Designer.cs new file mode 100644 index 0000000..b88cc9a --- /dev/null +++ b/Components/Components/VisualComponents/CustomListBox.Designer.cs @@ -0,0 +1,58 @@ +namespace Components.VisualComponents +{ + partial class CustomListBox + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + listBox = new ListBox(); + SuspendLayout(); + // + // listBox + // + listBox.Dock = DockStyle.Fill; + listBox.FormattingEnabled = true; + listBox.ItemHeight = 15; + listBox.Location = new Point(0, 0); + listBox.Name = "listBox"; + listBox.Size = new Size(300, 150); + listBox.TabIndex = 0; + // + // CustomListBox + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(listBox); + Name = "CustomListBox"; + Size = new Size(300, 150); + ResumeLayout(false); + } + + #endregion + + private ListBox listBox; + } +} diff --git a/Components/Components/VisualComponents/CustomListBox.cs b/Components/Components/VisualComponents/CustomListBox.cs new file mode 100644 index 0000000..5502c01 --- /dev/null +++ b/Components/Components/VisualComponents/CustomListBox.cs @@ -0,0 +1,162 @@ +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 Components.VisualComponents +{ + /// + /// Визуальный компонент для вывода списка в виде списка записей + /// + public partial class CustomListBox : UserControl + { + /// + /// Макетная строка + /// + private string _layoutString; + + /// + /// Символ начала имени свойства + /// + private string _startSymbol; + + /// + /// Символ конца имени свойства + /// + private string _endSymbol; + + /// + /// Индекс выбранной строки + /// + public int SelectedIndex + { + get + { + if (listBox.SelectedIndex == -1) + { + return -1; + } + + return listBox.SelectedIndex; + } + + set + { + if (listBox.SelectedItems.Count != 0) + { + listBox.SelectedIndex = value; + } + } + } + + /// + /// Конструктор + /// + public CustomListBox() + { + InitializeComponent(); + } + + /// + /// Установить макетную строку + /// + /// + /// + /// + public void SetLayoutInfo(string layoutString, string startSymbol, string endSymbol) + { + if (string.IsNullOrEmpty(layoutString) || string.IsNullOrEmpty(startSymbol) || string.IsNullOrEmpty(endSymbol)) + { + throw new Exception("Заполните макетную строку!"); + } + if (!layoutString.Contains(startSymbol) || !layoutString.Contains(endSymbol)) + { + throw new Exception("Макетная строка не содержит нужные элементы!"); + } + + _layoutString = layoutString; + _startSymbol = startSymbol; + _endSymbol = endSymbol; + } + + /// + /// Получить объект из выбранной строки + /// + /// + /// + public T? GetObject() where T : class, new() + { + if (listBox.SelectedIndex == -1) + { + return null; + } + + string selectedString = listBox.SelectedItem.ToString()!; + StringBuilder sb = new StringBuilder(selectedString); + T obj = new T(); + + foreach (var property in obj.GetType().GetProperties()) + { + if (!property.CanWrite) + { + continue; + } + + int firstBorder = sb.ToString().IndexOf(_startSymbol); + if (firstBorder == -1) + { + break; + } + + int secondBorder = sb.ToString().IndexOf(_endSymbol, firstBorder + 1); + if (secondBorder == -1) + { + break; + } + + string propertyValue = sb.ToString(firstBorder + 1, secondBorder - firstBorder - 1); + sb.Remove(0, secondBorder + 1); + property.SetValue(obj, Convert.ChangeType(propertyValue, property.PropertyType)); + } + + return obj; + } + + /// + /// Добавить объект в список + /// + /// + /// + /// + /// + public void AddObject(T obj) + { + if (obj == null) + { + throw new ArgumentNullException("Добавляемый объект не существует!"); + } + if (string.IsNullOrEmpty(_layoutString) || string.IsNullOrEmpty(_startSymbol) || string.IsNullOrEmpty(_endSymbol)) + { + throw new Exception("Заполните макетную строку!"); + } + if (!_layoutString.Contains(_startSymbol) || !_layoutString.Contains(_endSymbol)) + { + throw new Exception("Макетная строка не содержит нужные элементы!"); + } + + string processedString = _layoutString; + foreach (var property in obj.GetType().GetProperties()) + { + string placeholder = $"{_startSymbol}{property.Name}{_endSymbol}"; + processedString = processedString.Replace(placeholder, $"{_startSymbol}{property.GetValue(obj)}{_endSymbol}"); + } + + listBox.Items.Add(processedString); + } + } +} diff --git a/Components/Components/VisualComponents/CustomListBox.resx b/Components/Components/VisualComponents/CustomListBox.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Components/Components/VisualComponents/CustomListBox.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/Components/Components/VisualComponents/CustomTextBox.Designer.cs b/Components/Components/VisualComponents/CustomTextBox.Designer.cs new file mode 100644 index 0000000..d681cb9 --- /dev/null +++ b/Components/Components/VisualComponents/CustomTextBox.Designer.cs @@ -0,0 +1,71 @@ +namespace Components.VisualComponents +{ + partial class CustomTextBox + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + textBox = new TextBox(); + label = new Label(); + SuspendLayout(); + // + // textBox + // + textBox.Dock = DockStyle.Bottom; + textBox.Location = new Point(0, 30); + textBox.Name = "textBox"; + textBox.Size = new Size(170, 23); + textBox.TabIndex = 0; + textBox.TextChanged += textBox_TextChanged; + textBox.Enter += textBox_Enter; + // + // label + // + label.AutoSize = true; + label.Location = new Point(10, 10); + label.Name = "label"; + label.Size = new Size(32, 15); + label.TabIndex = 1; + label.Text = "Дата"; + // + // CustomTextBox + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(label); + Controls.Add(textBox); + Name = "CustomTextBox"; + Size = new Size(170, 53); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBox; + private Label label; + } +} diff --git a/Components/Components/VisualComponents/CustomTextBox.cs b/Components/Components/VisualComponents/CustomTextBox.cs new file mode 100644 index 0000000..c36773c --- /dev/null +++ b/Components/Components/VisualComponents/CustomTextBox.cs @@ -0,0 +1,146 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows.Forms; +using Components.VisualComponents.Exceptions; + +namespace Components.VisualComponents +{ + /// + /// Текстовый визуальный компонент для ввода значения с проверкой по шаблону + /// + public partial class CustomTextBox : UserControl + { + /// + /// Шаблон вводимого значения + /// + private string? _datePattern; + + /// + /// Шаблон вводимого значения + /// + public string? DatePattern + { + get { return _datePattern; } + set { _datePattern = value; } + } + + /// + /// Пример вводимого значения + /// + private string _dateExample = "01.01.1970"; + + /// + /// Введенное значение + /// + public string? TextBoxValue + { + get + { + if (DatePattern == null) + { + throw new NullPatternException("Шаблон не заполнен!"); + } + + Regex regex = new Regex(DatePattern); + bool isValid = regex.IsMatch(textBox.Text); + if (isValid) + { + return textBox.Text; + } + else + { + throw new InvalidInputException(textBox.Text); + } + } + + set + { + Regex regex = new Regex(DatePattern!); + bool isValid = regex.IsMatch(value); + if (isValid) + { + textBox.Text = value; + } + else + { + throw new InvalidInputException(textBox.Text); + } + } + } + + /// + /// Событие, вызываемое при смене значения + /// + private EventHandler _onValueChangedEvent; + + /// + /// Событие, вызываемое при смене значения + /// + public event EventHandler ValueChanged + { + add + { + _onValueChangedEvent += value; + } + + remove + { + _onValueChangedEvent -= value; + } + } + + /// + /// Конструктор + /// + public CustomTextBox() + { + InitializeComponent(); + } + + /// + /// Заполнить пример вводимого значения + /// + /// + public bool SetDateExample(string date) + { + Regex regex = new Regex(DatePattern!); + bool isValid = regex.IsMatch(date); + if (isValid) + { + _dateExample = date; + return true; + } + + return false; + } + + /// + /// Вывод подсказки с примером правильного ввода + /// + /// + /// + private void textBox_Enter(object sender, EventArgs e) + { + int visibleTime = 2000; + ToolTip tooltip = new ToolTip(); + tooltip.Show(_dateExample, textBox, 30, -20, visibleTime); + } + + /// + /// Смена значения + /// + /// + /// + private void textBox_TextChanged(object sender, EventArgs e) + { + _onValueChangedEvent?.Invoke(sender, e); + } + } +} diff --git a/Components/Components/VisualComponents/CustomTextBox.resx b/Components/Components/VisualComponents/CustomTextBox.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Components/Components/VisualComponents/CustomTextBox.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/Components/Components/VisualComponents/Exceptions/InvalidInputException.cs b/Components/Components/VisualComponents/Exceptions/InvalidInputException.cs new file mode 100644 index 0000000..5457361 --- /dev/null +++ b/Components/Components/VisualComponents/Exceptions/InvalidInputException.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Components.VisualComponents.Exceptions +{ + /// + /// Исключение, вызываемое, когда введенное значение не соответствует шаблону + /// + public class InvalidInputException : Exception + { + /// + /// Конструктор по умолчанию + /// + public InvalidInputException() { } + + /// + /// Констурктор с сообщением + /// + /// + public InvalidInputException(string message) : base($"{message} не соответствует шаблону!") { } + } +} diff --git a/Components/Components/VisualComponents/Exceptions/NullPatternException.cs b/Components/Components/VisualComponents/Exceptions/NullPatternException.cs new file mode 100644 index 0000000..ba30822 --- /dev/null +++ b/Components/Components/VisualComponents/Exceptions/NullPatternException.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Components.VisualComponents.Exceptions +{ + /// + /// Исключение, вызываемое, когда шаблон не установлен + /// + public class NullPatternException : Exception + { + /// + /// Конструктор по умолчанию + /// + public NullPatternException() { } + + /// + /// Констурктор с сообщением + /// + /// + public NullPatternException(string message) : base(message) { } + } +} diff --git a/Components/WinForms/FormComponents.Designer.cs b/Components/WinForms/FormComponents.Designer.cs index 56d7c21..e7d62ac 100644 --- a/Components/WinForms/FormComponents.Designer.cs +++ b/Components/WinForms/FormComponents.Designer.cs @@ -28,18 +28,245 @@ /// private void InitializeComponent() { + groupBox1 = new GroupBox(); + labelItem = new Label(); + buttonGetItem = new Button(); + buttonClearItems = new Button(); + buttonAddItems = new Button(); + customComboBox = new Components.VisualComponents.CustomComboBox(); + groupBox2 = new GroupBox(); + buttonSetDateExample = new Button(); + textBoxDateExample = new TextBox(); + checkBoxValidate = new CheckBox(); + buttonValidate = new Button(); + customTextBox = new Components.VisualComponents.CustomTextBox(); + groupBox3 = new GroupBox(); + labelObjectInfo = new Label(); + buttonGetObject = new Button(); + buttonAddObjects = new Button(); + customListBox = new Components.VisualComponents.CustomListBox(); + groupBox1.SuspendLayout(); + groupBox2.SuspendLayout(); + groupBox3.SuspendLayout(); SuspendLayout(); // + // groupBox1 + // + groupBox1.Controls.Add(labelItem); + groupBox1.Controls.Add(buttonGetItem); + groupBox1.Controls.Add(buttonClearItems); + groupBox1.Controls.Add(buttonAddItems); + groupBox1.Controls.Add(customComboBox); + groupBox1.Dock = DockStyle.Left; + groupBox1.Location = new Point(0, 0); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(275, 461); + groupBox1.TabIndex = 0; + groupBox1.TabStop = false; + groupBox1.Text = "Тест для ComboBox"; + // + // labelItem + // + labelItem.AutoSize = true; + labelItem.BorderStyle = BorderStyle.Fixed3D; + labelItem.Font = new Font("Segoe UI", 11F, FontStyle.Regular, GraphicsUnit.Point); + labelItem.Location = new Point(143, 140); + labelItem.Name = "labelItem"; + labelItem.Size = new Size(70, 22); + labelItem.TabIndex = 4; + labelItem.Text = "Элемент"; + // + // buttonGetItem + // + buttonGetItem.Location = new Point(12, 139); + buttonGetItem.Name = "buttonGetItem"; + buttonGetItem.Size = new Size(125, 23); + buttonGetItem.TabIndex = 3; + buttonGetItem.Text = "Получить элемент"; + buttonGetItem.UseVisualStyleBackColor = true; + buttonGetItem.Click += buttonGetItem_Click; + // + // buttonClearItems + // + buttonClearItems.Location = new Point(12, 110); + buttonClearItems.Name = "buttonClearItems"; + buttonClearItems.Size = new Size(125, 23); + buttonClearItems.TabIndex = 2; + buttonClearItems.Text = "Очистить элементы"; + buttonClearItems.UseVisualStyleBackColor = true; + buttonClearItems.Click += buttonClearItems_Click; + // + // buttonAddItems + // + buttonAddItems.Location = new Point(12, 81); + buttonAddItems.Name = "buttonAddItems"; + buttonAddItems.Size = new Size(125, 23); + buttonAddItems.TabIndex = 1; + buttonAddItems.Text = "Добавить элементы"; + buttonAddItems.UseVisualStyleBackColor = true; + buttonAddItems.Click += buttonAddItems_Click; + // + // customComboBox + // + customComboBox.Location = new Point(12, 22); + customComboBox.Name = "customComboBox"; + customComboBox.SelectedItem = ""; + customComboBox.Size = new Size(257, 53); + customComboBox.TabIndex = 0; + // + // groupBox2 + // + groupBox2.Controls.Add(buttonSetDateExample); + groupBox2.Controls.Add(textBoxDateExample); + groupBox2.Controls.Add(checkBoxValidate); + groupBox2.Controls.Add(buttonValidate); + groupBox2.Controls.Add(customTextBox); + groupBox2.Dock = DockStyle.Left; + groupBox2.Location = new Point(275, 0); + groupBox2.Name = "groupBox2"; + groupBox2.Size = new Size(253, 461); + groupBox2.TabIndex = 1; + groupBox2.TabStop = false; + groupBox2.Text = "Тест для TextBox"; + // + // buttonSetDateExample + // + buttonSetDateExample.Location = new Point(64, 168); + buttonSetDateExample.Name = "buttonSetDateExample"; + buttonSetDateExample.Size = new Size(125, 23); + buttonSetDateExample.TabIndex = 4; + buttonSetDateExample.Text = "Изменить пример"; + buttonSetDateExample.UseVisualStyleBackColor = true; + buttonSetDateExample.Click += buttonSetDateExample_Click; + // + // textBoxDateExample + // + textBoxDateExample.Location = new Point(6, 139); + textBoxDateExample.Name = "textBoxDateExample"; + textBoxDateExample.PlaceholderText = "01.01.1970"; + textBoxDateExample.Size = new Size(241, 23); + textBoxDateExample.TabIndex = 3; + // + // checkBoxValidate + // + checkBoxValidate.AutoSize = true; + checkBoxValidate.Enabled = false; + checkBoxValidate.Location = new Point(167, 84); + checkBoxValidate.Name = "checkBoxValidate"; + checkBoxValidate.RightToLeft = RightToLeft.No; + checkBoxValidate.Size = new Size(80, 19); + checkBoxValidate.TabIndex = 2; + checkBoxValidate.Text = "Проверка"; + checkBoxValidate.UseVisualStyleBackColor = true; + // + // buttonValidate + // + buttonValidate.Location = new Point(6, 81); + buttonValidate.Name = "buttonValidate"; + buttonValidate.Size = new Size(75, 23); + buttonValidate.TabIndex = 1; + buttonValidate.Text = "Проверка"; + buttonValidate.UseVisualStyleBackColor = true; + buttonValidate.Click += buttonValidate_Click; + // + // customTextBox + // + customTextBox.DatePattern = null; + customTextBox.Location = new Point(6, 22); + customTextBox.Name = "customTextBox"; + customTextBox.Size = new Size(241, 53); + customTextBox.TabIndex = 0; + // + // groupBox3 + // + groupBox3.Controls.Add(labelObjectInfo); + groupBox3.Controls.Add(buttonGetObject); + groupBox3.Controls.Add(buttonAddObjects); + groupBox3.Controls.Add(customListBox); + groupBox3.Dock = DockStyle.Right; + groupBox3.Location = new Point(534, 0); + groupBox3.Name = "groupBox3"; + groupBox3.Size = new Size(350, 461); + groupBox3.TabIndex = 2; + groupBox3.TabStop = false; + groupBox3.Text = "Тест для ListBox"; + // + // labelObjectInfo + // + labelObjectInfo.AutoSize = true; + labelObjectInfo.BorderStyle = BorderStyle.Fixed3D; + labelObjectInfo.Font = new Font("Segoe UI", 11F, FontStyle.Regular, GraphicsUnit.Point); + labelObjectInfo.Location = new Point(132, 426); + labelObjectInfo.Name = "labelObjectInfo"; + labelObjectInfo.Size = new Size(190, 22); + labelObjectInfo.TabIndex = 3; + labelObjectInfo.Text = " Информация об объекте"; + // + // buttonGetObject + // + buttonGetObject.Location = new Point(6, 426); + buttonGetObject.Name = "buttonGetObject"; + buttonGetObject.Size = new Size(120, 23); + buttonGetObject.TabIndex = 2; + buttonGetObject.Text = "Получить объект"; + buttonGetObject.UseVisualStyleBackColor = true; + buttonGetObject.Click += buttonGetObject_Click; + // + // buttonAddObjects + // + buttonAddObjects.Location = new Point(6, 397); + buttonAddObjects.Name = "buttonAddObjects"; + buttonAddObjects.Size = new Size(120, 23); + buttonAddObjects.TabIndex = 1; + buttonAddObjects.Text = "Добавить объекты"; + buttonAddObjects.UseVisualStyleBackColor = true; + buttonAddObjects.Click += buttonAddObjects_Click; + // + // customListBox + // + customListBox.Location = new Point(6, 22); + customListBox.Name = "customListBox"; + customListBox.SelectedIndex = -1; + customListBox.Size = new Size(332, 369); + customListBox.TabIndex = 0; + // // FormComponents // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(884, 461); + Controls.Add(groupBox3); + Controls.Add(groupBox2); + Controls.Add(groupBox1); Name = "FormComponents"; Text = "Компоненты"; + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); + groupBox2.ResumeLayout(false); + groupBox2.PerformLayout(); + groupBox3.ResumeLayout(false); + groupBox3.PerformLayout(); ResumeLayout(false); } #endregion + + private GroupBox groupBox1; + private GroupBox groupBox2; + private GroupBox groupBox3; + private Button buttonAddObjects; + private Components.VisualComponents.CustomListBox customListBox; + private Label labelObjectInfo; + private Button buttonGetObject; + private Button buttonAddItems; + private Components.VisualComponents.CustomComboBox customComboBox; + private Button buttonGetItem; + private Button buttonClearItems; + private Label labelItem; + private CheckBox checkBoxValidate; + private Button buttonValidate; + private Components.VisualComponents.CustomTextBox customTextBox; + private Button buttonSetDateExample; + private TextBox textBoxDateExample; } } diff --git a/Components/WinForms/FormComponents.cs b/Components/WinForms/FormComponents.cs index 5b1dda1..eea6e9a 100644 --- a/Components/WinForms/FormComponents.cs +++ b/Components/WinForms/FormComponents.cs @@ -1,10 +1,134 @@ namespace WinForms { + /// + /// + /// public partial class FormComponents : Form { + /// + /// + /// public FormComponents() { InitializeComponent(); + + customComboBox.AddItem(" 1"); + customComboBox.AddItem(" 2"); + customComboBox.AddItem(" 3"); + + customTextBox.DatePattern = @"^(\d{2}.\d{2}.\d{4})$"; + + customListBox.SetLayoutInfo(" *Name* *Surname*", "*", "*"); + } + + /// + /// customComboBox + /// + /// + /// + private void buttonAddItems_Click(object sender, EventArgs e) + { + customComboBox.AddItem(" 3"); + customComboBox.AddItem(" 4"); + customComboBox.AddItem(" 5"); + } + + /// + /// customComboBox + /// + /// + /// + private void buttonClearItems_Click(object sender, EventArgs e) + { + customComboBox.Clear(); + } + + /// + /// customComboBox + /// + /// + /// + private void buttonGetItem_Click(object sender, EventArgs e) + { + labelItem.Text = customComboBox.SelectedItem.ToString(); + } + + /// + /// customTextBox + /// + /// + /// + private void buttonValidate_Click(object sender, EventArgs e) + { + try + { + if (customTextBox.TextBoxValue != null) + { + checkBoxValidate.Text = ""; + checkBoxValidate.Checked = true; + checkBoxValidate.BackColor = Color.LightGreen; + } + } + catch (Exception ex) + { + checkBoxValidate.Text = " "; + checkBoxValidate.Checked = false; + checkBoxValidate.BackColor = Color.Red; + + MessageBox.Show(ex.Message); + } + } + + /// + /// customTextBox + /// + /// + /// + private void buttonSetDateExample_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxDateExample.Text)) + { + return; + } + + if (customTextBox.SetDateExample(textBoxDateExample.Text)) + { + MessageBox.Show(" !", "", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show(" !", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// customListBox + /// + /// + /// + private void buttonAddObjects_Click(object sender, EventArgs e) + { + customListBox.AddObject(new Person("", "")); + customListBox.AddObject(new Person("", "")); + customListBox.AddObject(new Person("", "")); + } + + /// + /// customListBox + /// + /// + /// + private void buttonGetObject_Click(object sender, EventArgs e) + { + Person person = customListBox.GetObject(); + if (person == null) + { + labelObjectInfo.Text = " "; + return; + } + + string objectInfo = person.Name + " " + person.Surname; + labelObjectInfo.Text = objectInfo; } } } diff --git a/Components/WinForms/Person.cs b/Components/WinForms/Person.cs new file mode 100644 index 0000000..78f8acd --- /dev/null +++ b/Components/WinForms/Person.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinForms +{ + /// + /// Сущность "Человек" + /// + public class Person + { + /// + /// Имя + /// + public string Name { get; set; } + + /// + /// Фамилия + /// + public string Surname { get; set; } + + /// + /// Конструктор по умолчанию + /// + public Person() { } + + /// + /// Конструктор с параметрами + /// + /// + /// + public Person(string name, string surname) + { + Name = name; + Surname = surname; + } + } +} diff --git a/Components/WinForms/WinForms.csproj b/Components/WinForms/WinForms.csproj index b57c89e..a813ce4 100644 --- a/Components/WinForms/WinForms.csproj +++ b/Components/WinForms/WinForms.csproj @@ -8,4 +8,8 @@ enable + + + + \ No newline at end of file