Compare commits

...

2 Commits

Author SHA1 Message Date
c2fd197628 Fixes 2024-09-06 10:30:57 +04:00
1d7d23e749 LabWork01 2024-09-05 18:58:41 +04:00
15 changed files with 1418 additions and 1 deletions

View File

@ -0,0 +1,72 @@
namespace Components.VisualComponents
{
partial class CustomComboBox
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
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;
}
}

View File

@ -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
{
/// <summary>
/// Визуальный компонент для выбора из выпадающего списка
/// </summary>
public partial class CustomComboBox : UserControl
{
/// <summary>
/// Событие, вызываемое при смене значения
/// </summary>
private EventHandler _onValueChangedEvent;
/// <summary>
/// Событие, вызываемое при смене значения
/// </summary>
public event EventHandler ValueChanged
{
add
{
_onValueChangedEvent += value;
}
remove
{
_onValueChangedEvent -= value;
}
}
/// <summary>
/// Выбранный элемент
/// </summary>
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;
}
}
}
/// <summary>
/// Конструктор
/// </summary>
public CustomComboBox()
{
InitializeComponent();
}
/// <summary>
/// Добавить элемент
/// </summary>
/// <param name="item"></param>
public void AddItem(string item)
{
if (item == null)
{
return;
}
comboBox.Items.Add(item);
}
/// <summary>
/// Очистить список
/// </summary>
public void Clear()
{
comboBox.Items.Clear();
}
/// <summary>
/// Смена значения
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboBox_SelectedValueChanged(object sender, EventArgs e)
{
_onValueChangedEvent?.Invoke(sender, e);
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,58 @@
namespace Components.VisualComponents
{
partial class CustomListBox
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
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;
}
}

View File

@ -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
{
/// <summary>
/// Визуальный компонент для вывода списка в виде списка записей
/// </summary>
public partial class CustomListBox : UserControl
{
/// <summary>
/// Макетная строка
/// </summary>
private string _layoutString;
/// <summary>
/// Символ начала имени свойства
/// </summary>
private string _startSymbol;
/// <summary>
/// Символ конца имени свойства
/// </summary>
private string _endSymbol;
/// <summary>
/// Индекс выбранной строки
/// </summary>
public int SelectedIndex
{
get
{
if (listBox.SelectedIndex == -1)
{
return -1;
}
return listBox.SelectedIndex;
}
set
{
if (listBox.SelectedItems.Count != 0)
{
listBox.SelectedIndex = value;
}
}
}
/// <summary>
/// Конструктор
/// </summary>
public CustomListBox()
{
InitializeComponent();
}
/// <summary>
/// Установить макетную строку
/// </summary>
/// <param name="layoutString"></param>
/// <param name="startSymbol"></param>
/// <param name="endSymbol"></param>
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;
}
/// <summary>
/// Получить объект из выбранной строки
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public T? GetObject<T>() 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;
}
/// <summary>
/// Добавить объект в список
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="Exception"></exception>
public void AddObject<T>(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);
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,71 @@
namespace Components.VisualComponents
{
partial class CustomTextBox
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
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;
}
}

View File

@ -0,0 +1,142 @@
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
{
/// <summary>
/// Текстовый визуальный компонент для ввода значения с проверкой по шаблону
/// </summary>
public partial class CustomTextBox : UserControl
{
/// <summary>
/// Шаблон вводимого значения
/// </summary>
private string? _datePattern;
/// <summary>
/// Шаблон вводимого значения
/// </summary>
public string? DatePattern
{
get { return _datePattern; }
set { _datePattern = value; }
}
/// <summary>
/// Пример вводимого значения
/// </summary>
private string _dateExample = "01.01.1970";
/// <summary>
/// Введенное значение
/// </summary>
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;
}
}
}
/// <summary>
/// Событие, вызываемое при смене значения
/// </summary>
private EventHandler _onValueChangedEvent;
/// <summary>
/// Событие, вызываемое при смене значения
/// </summary>
public event EventHandler ValueChanged
{
add
{
_onValueChangedEvent += value;
}
remove
{
_onValueChangedEvent -= value;
}
}
/// <summary>
/// Конструктор
/// </summary>
public CustomTextBox()
{
InitializeComponent();
}
/// <summary>
/// Заполнить пример вводимого значения
/// </summary>
/// <param name="date"></param>
public bool SetDateExample(string date)
{
Regex regex = new Regex(DatePattern!);
bool isValid = regex.IsMatch(date);
if (isValid)
{
_dateExample = date;
return true;
}
return false;
}
/// <summary>
/// Вывод подсказки с примером правильного ввода
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void textBox_Enter(object sender, EventArgs e)
{
int visibleTime = 2000;
ToolTip tooltip = new ToolTip();
tooltip.Show(_dateExample, textBox, 30, -20, visibleTime);
}
/// <summary>
/// Смена значения
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void textBox_TextChanged(object sender, EventArgs e)
{
_onValueChangedEvent?.Invoke(sender, e);
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Components.VisualComponents.Exceptions
{
/// <summary>
/// Исключение, вызываемое, когда введенное значение не соответствует шаблону
/// </summary>
public class InvalidInputException : Exception
{
/// <summary>
/// Конструктор по умолчанию
/// </summary>
public InvalidInputException() { }
/// <summary>
/// Констурктор с сообщением
/// </summary>
/// <param name="message"></param>
public InvalidInputException(string message) : base($"{message} не соответствует шаблону!") { }
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Components.VisualComponents.Exceptions
{
/// <summary>
/// Исключение, вызываемое, когда шаблон не установлен
/// </summary>
public class NullPatternException : Exception
{
/// <summary>
/// Конструктор по умолчанию
/// </summary>
public NullPatternException() { }
/// <summary>
/// Констурктор с сообщением
/// </summary>
/// <param name="message"></param>
public NullPatternException(string message) : base(message) { }
}
}

View File

@ -28,18 +28,245 @@
/// </summary> /// </summary>
private void InitializeComponent() 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(); 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 // FormComponents
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450); ClientSize = new Size(884, 461);
Controls.Add(groupBox3);
Controls.Add(groupBox2);
Controls.Add(groupBox1);
Name = "FormComponents"; Name = "FormComponents";
Text = "Компоненты"; Text = "Компоненты";
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
groupBox2.ResumeLayout(false);
groupBox2.PerformLayout();
groupBox3.ResumeLayout(false);
groupBox3.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
} }
#endregion #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;
} }
} }

View File

@ -1,10 +1,134 @@
namespace WinForms namespace WinForms
{ {
/// <summary>
/// Îñíîâíàÿ ôîðìà
/// </summary>
public partial class FormComponents : Form public partial class FormComponents : Form
{ {
/// <summary>
/// Êîíñòðóêòîð
/// </summary>
public FormComponents() public FormComponents()
{ {
InitializeComponent(); InitializeComponent();
customComboBox.AddItem("Ýëåìåíò 1");
customComboBox.AddItem("Ýëåìåíò 2");
customComboBox.AddItem("Ýëåìåíò 3");
customTextBox.DatePattern = @"^(\d{2}.\d{2}.\d{4})$";
customListBox.SetLayoutInfo("Èìÿ *Name* Ôàìèëèÿ *Surname*", "*", "*");
}
/// <summary>
/// Äîáàâèòü ýäåìåíòû â customComboBox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAddItems_Click(object sender, EventArgs e)
{
customComboBox.AddItem("Ýëåìåíò 3");
customComboBox.AddItem("Ýëåìåíò 4");
customComboBox.AddItem("Ýëåìåíò 5");
}
/// <summary>
/// Î÷èñòèòü ñïèñîê ýëåìåíòîâ customComboBox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonClearItems_Click(object sender, EventArgs e)
{
customComboBox.Clear();
}
/// <summary>
/// Ïîëó÷èòü âûáðàííûé ýëåìåíò èç customComboBox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonGetItem_Click(object sender, EventArgs e)
{
labelItem.Text = customComboBox.SelectedItem.ToString();
}
/// <summary>
/// Ïðîâåðêà ââåäåííîãî çíà÷åíèÿ ñ çàäàííûì øàáëîíîì customTextBox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
/// <summary>
/// Èçìåíèòü ïðèìåð çàäàííîãî øàáëîíà customTextBox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
/// <summary>
/// Äîáàâèòü îáúåêòû â customListBox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAddObjects_Click(object sender, EventArgs e)
{
customListBox.AddObject<Person>(new Person("Åâãåíèé", "Ýãîâ"));
customListBox.AddObject<Person>(new Person("Àíòîí", "Ñêàëêèí"));
customListBox.AddObject<Person>(new Person("Ìàêñèì", "Ìàñåíüêèí"));
}
/// <summary>
/// Ïîëó÷èòü îáúåêò èç customListBox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonGetObject_Click(object sender, EventArgs e)
{
Person person = customListBox.GetObject<Person>();
if (person == null)
{
labelObjectInfo.Text = "Îáúåêò íå íàéäåí";
return;
}
string objectInfo = person.Name + " " + person.Surname;
labelObjectInfo.Text = objectInfo;
} }
} }
} }

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WinForms
{
/// <summary>
/// Сущность "Человек"
/// </summary>
public class Person
{
/// <summary>
/// Имя
/// </summary>
public string Name { get; set; }
/// <summary>
/// Фамилия
/// </summary>
public string Surname { get; set; }
/// <summary>
/// Конструктор по умолчанию
/// </summary>
public Person() { }
/// <summary>
/// Конструктор с параметрами
/// </summary>
/// <param name="name"></param>
/// <param name="surname"></param>
public Person(string name, string surname)
{
Name = name;
Surname = surname;
}
}
}

View File

@ -8,4 +8,8 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Components\Components.csproj" />
</ItemGroup>
</Project> </Project>