Compare commits

...

2 Commits
main ... lab1

Author SHA1 Message Date
Илья
cf9dc68b63 lab1 ready 2024-09-21 11:26:26 +04:00
Илья
6c59744189 Make ComboBox and TextBox 2024-09-05 23:36:10 +04:00
19 changed files with 1097 additions and 77 deletions

View File

@ -0,0 +1,16 @@
using System.Runtime.Serialization;
namespace RodionovLibrary.Exceptions
{
[Serializable]
public class NotMatchPatternException : ApplicationException
{
public NotMatchPatternException() : base() { }
public NotMatchPatternException(string message) : base(message) { }
public NotMatchPatternException(string message, Exception exception) : base(message, exception) { }
protected NotMatchPatternException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}
}

View File

@ -0,0 +1,16 @@
using System.Runtime.Serialization;
namespace RodionovLibrary.Exceptions
{
[Serializable]
public class NullPatternException : ApplicationException
{
public NullPatternException() : base() { }
public NullPatternException(string message) : base(message) { }
public NullPatternException(string message, Exception exception) : base(message, exception) { }
protected NullPatternException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}
}

View File

@ -0,0 +1,59 @@
namespace RodionovLibrary.VisualComponents
{
partial class ComboBoxControl
{
/// <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();
SuspendLayout();
//
// comboBox
//
comboBox.FormattingEnabled = true;
comboBox.Location = new Point(1, 0);
comboBox.Name = "comboBox";
comboBox.Size = new Size(181, 23);
comboBox.TabIndex = 0;
comboBox.SelectedIndexChanged += ComboBox_SelectedIndexChanged;
//
// ComboBoxControl
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
AutoSize = true;
AutoSizeMode = AutoSizeMode.GrowAndShrink;
Controls.Add(comboBox);
Name = "ComboBoxControl";
Size = new Size(185, 26);
ResumeLayout(false);
}
#endregion
private ComboBox comboBox;
}
}

View File

@ -0,0 +1,51 @@
namespace RodionovLibrary.VisualComponents
{
public partial class ComboBoxControl : UserControl
{
private event EventHandler? _valueChanged;
public event EventHandler ValueChanged
{
add { _valueChanged += value; }
remove { _valueChanged -= value; }
}
public string SelectedValue
{
get
{
return comboBox.SelectedItem != null ? comboBox.SelectedItem.ToString()! : "";
}
set
{
if (comboBox.Items.Contains(value))
{
comboBox.SelectedItem = value;
}
}
}
public ComboBoxControl()
{
InitializeComponent();
}
public void AddItems(List<string> items)
{
foreach (string item in items)
{
comboBox.Items.Add(item);
}
}
public void Clear()
{
comboBox.Items.Clear();
}
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
_valueChanged?.Invoke(sender, e);
}
}
}

View File

@ -0,0 +1,59 @@
namespace RodionovLibrary.VisualComponents
{
partial class ListBoxControl
{
/// <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.FormattingEnabled = true;
listBox.ItemHeight = 15;
listBox.Location = new Point(0, 0);
listBox.Name = "listBox";
listBox.Size = new Size(564, 364);
listBox.TabIndex = 0;
//
// ListBoxControl
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
AutoSize = true;
AutoSizeMode = AutoSizeMode.GrowAndShrink;
Controls.Add(listBox);
Name = "ListBoxControl";
Size = new Size(564, 150);
ResumeLayout(false);
}
#endregion
private ListBox listBox;
}
}

View File

@ -0,0 +1,93 @@
using System.Reflection;
namespace RodionovLibrary.VisualComponents
{
public partial class ListBoxControl : UserControl
{
private string? _template;
private char? _fromChar;
private char? _toChar;
public int SelectedIndex
{
get
{
return listBox.SelectedIndex;
}
set
{
listBox.SelectedIndex = value;
}
}
public ListBoxControl()
{
InitializeComponent();
}
public void SetParams(string template, char fromChar, char toChar)
{
_template = template;
_fromChar = fromChar;
_toChar = toChar;
}
public T? GetObject<T>()
{
if (listBox.SelectedIndex == -1 || string.IsNullOrEmpty(_template) || !_fromChar.HasValue || !_toChar.HasValue)
throw new ArgumentException("Не хватает данных");
var type = typeof(T);
var properties = type.GetProperties();
var curObject = Activator.CreateInstance(type);
string[] wordsTemplate = _template.Split(' ');
string[] words = listBox.SelectedItem.ToString().Split(' ');
for (int i = 0; i < wordsTemplate.Length; i++)
{
string word = wordsTemplate[i];
if (word.Contains(_fromChar.Value) && word.Contains(_toChar.Value))
{
int startCharIndex = word.IndexOf(_fromChar.Value);
int endCharIndex = word.LastIndexOf(_toChar.Value);
string propertyName = word.Substring(startCharIndex + 1, endCharIndex - startCharIndex - 1);
var property = properties.FirstOrDefault(x => x.Name == propertyName);
if (property == null)
continue;
int extraCharsBefore = startCharIndex;
int extraCharsAfter = word.Length - endCharIndex - 1;
string propertyValue = words[i].Substring(extraCharsBefore,
words[i].Length - extraCharsBefore - extraCharsAfter);
property.SetValue(curObject, Convert.ChangeType(propertyValue, property.PropertyType));
}
}
return (T?)curObject;
}
public void AddItems<T>(List<T> items)
where T : class
{
if (string.IsNullOrEmpty(_template) || !_fromChar.HasValue || !_toChar.HasValue)
throw new ArgumentException("Не хватает данных");
listBox.Items.Clear();
var type = typeof(T);
var properties = type.GetProperties();
foreach (T item in items)
{
string result = _template;
foreach (var property in properties)
{
string search = _fromChar.Value + property.Name + _toChar.Value;
result = result.Replace(search, property.GetValue(item)?.ToString() ?? "");
}
listBox.Items.Add(result);
}
}
}
}

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,63 @@
namespace RodionovLibrary.VisualComponents
{
partial class TextBoxControl
{
/// <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()
{
components = new System.ComponentModel.Container();
textBox = new TextBox();
toolTip = new ToolTip(components);
SuspendLayout();
//
// textBox
//
textBox.Location = new Point(0, 0);
textBox.Name = "textBox";
textBox.Size = new Size(213, 23);
textBox.TabIndex = 0;
textBox.TextChanged += TextBox_TextChanged;
textBox.MouseEnter += TextBox_MouseEnter;
//
// TextBoxControl
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
AutoSize = true;
AutoSizeMode = AutoSizeMode.GrowAndShrink;
Controls.Add(textBox);
Name = "TextBoxControl";
Size = new Size(216, 26);
ResumeLayout(false);
PerformLayout();
}
#endregion
private TextBox textBox;
private ToolTip toolTip;
}
}

View File

@ -0,0 +1,58 @@
using RodionovLibrary.Exceptions;
using System.Text.RegularExpressions;
namespace RodionovLibrary.VisualComponents
{
public partial class TextBoxControl : UserControl
{
private string? tooltipText;
private event EventHandler? _valueChanged;
public event EventHandler ValueChanged
{
add { _valueChanged += value; }
remove { _valueChanged -= value; }
}
public string? Pattern { get; set; }
public string Value {
get
{
if (string.IsNullOrEmpty(Pattern))
throw new NullPatternException("Не задан шаблон");
if (!new Regex(Pattern).IsMatch(textBox.Text))
throw new NotMatchPatternException("Введенное значение не соответствует шаблону");
return textBox.Text;
}
set
{
if (!string.IsNullOrEmpty(Pattern) && new Regex(Pattern).IsMatch(value))
textBox.Text = value;
}
}
public TextBoxControl()
{
InitializeComponent();
}
public void SetTooltipText(string text)
{
tooltipText = text;
}
private void TextBox_TextChanged(object sender, EventArgs e)
{
_valueChanged?.Invoke(sender, e);
Value = textBox.Text;
}
private void TextBox_MouseEnter(object sender, EventArgs e)
{
toolTip.Show(tooltipText ?? "", textBox, 45, 20, 3000);
}
}
}

View File

@ -0,0 +1,123 @@
<?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>
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -1,39 +0,0 @@
namespace WinForms
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace WinForms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

206
COP/WinForms/FormTest.Designer.cs generated Normal file
View File

@ -0,0 +1,206 @@
namespace WinForms
{
partial class FormTest
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
comboBoxControl = new RodionovLibrary.VisualComponents.ComboBoxControl();
listBoxControl = new RodionovLibrary.VisualComponents.ListBoxControl();
textBoxControl = new RodionovLibrary.VisualComponents.TextBoxControl();
buttonClear = new Button();
buttonGetComboBox = new Button();
buttonSetComboBox = new Button();
buttonGetTextBox = new Button();
buttonSetTextBox = new Button();
buttonSetWrongTextBox = new Button();
buttonGetObject = new Button();
buttonGetIndex = new Button();
buttonSetIndex = new Button();
SuspendLayout();
//
// comboBoxControl
//
comboBoxControl.AutoSize = true;
comboBoxControl.AutoSizeMode = AutoSizeMode.GrowAndShrink;
comboBoxControl.Location = new Point(45, 27);
comboBoxControl.Margin = new Padding(3, 4, 3, 4);
comboBoxControl.Name = "comboBoxControl";
comboBoxControl.SelectedValue = "";
comboBoxControl.Size = new Size(210, 32);
comboBoxControl.TabIndex = 0;
//
// listBoxControl
//
listBoxControl.AutoSize = true;
listBoxControl.AutoSizeMode = AutoSizeMode.GrowAndShrink;
listBoxControl.Location = new Point(45, 276);
listBoxControl.Margin = new Padding(3, 4, 3, 4);
listBoxControl.Name = "listBoxControl";
listBoxControl.SelectedIndex = -1;
listBoxControl.Size = new Size(647, 488);
listBoxControl.TabIndex = 1;
//
// textBoxControl
//
textBoxControl.AutoSize = true;
textBoxControl.AutoSizeMode = AutoSizeMode.GrowAndShrink;
textBoxControl.Location = new Point(446, 27);
textBoxControl.Margin = new Padding(3, 4, 3, 4);
textBoxControl.Name = "textBoxControl";
textBoxControl.Pattern = null;
textBoxControl.Size = new Size(246, 31);
textBoxControl.TabIndex = 2;
//
// buttonClear
//
buttonClear.Location = new Point(47, 66);
buttonClear.Name = "buttonClear";
buttonClear.Size = new Size(94, 29);
buttonClear.TabIndex = 3;
buttonClear.Text = "Отчистка";
buttonClear.UseVisualStyleBackColor = true;
buttonClear.Click += ButtonClear_Click;
//
// buttonGetComboBox
//
buttonGetComboBox.Location = new Point(47, 114);
buttonGetComboBox.Name = "buttonGetComboBox";
buttonGetComboBox.Size = new Size(165, 29);
buttonGetComboBox.TabIndex = 4;
buttonGetComboBox.Text = "Получение значения";
buttonGetComboBox.UseVisualStyleBackColor = true;
buttonGetComboBox.Click += ButtonGetComboBox_Click;
//
// buttonSetComboBox
//
buttonSetComboBox.Location = new Point(47, 165);
buttonSetComboBox.Name = "buttonSetComboBox";
buttonSetComboBox.Size = new Size(165, 29);
buttonSetComboBox.TabIndex = 5;
buttonSetComboBox.Text = "Установка значения";
buttonSetComboBox.UseVisualStyleBackColor = true;
buttonSetComboBox.Click += ButtonSetComboBox_Click;
//
// buttonGetTextBox
//
buttonGetTextBox.Location = new Point(446, 66);
buttonGetTextBox.Name = "buttonGetTextBox";
buttonGetTextBox.Size = new Size(165, 29);
buttonGetTextBox.TabIndex = 6;
buttonGetTextBox.Text = "Получение значения";
buttonGetTextBox.UseVisualStyleBackColor = true;
buttonGetTextBox.Click += ButtonGetTextBox_Click;
//
// buttonSetTextBox
//
buttonSetTextBox.Location = new Point(446, 114);
buttonSetTextBox.Name = "buttonSetTextBox";
buttonSetTextBox.Size = new Size(165, 29);
buttonSetTextBox.TabIndex = 7;
buttonSetTextBox.Text = "Установка значения";
buttonSetTextBox.UseVisualStyleBackColor = true;
buttonSetTextBox.Click += ButtonSetTextBox_Click;
//
// buttonSetWrongTextBox
//
buttonSetWrongTextBox.Location = new Point(446, 165);
buttonSetWrongTextBox.Name = "buttonSetWrongTextBox";
buttonSetWrongTextBox.Size = new Size(246, 29);
buttonSetWrongTextBox.TabIndex = 8;
buttonSetWrongTextBox.Text = "Установка значения (неверное)";
buttonSetWrongTextBox.UseVisualStyleBackColor = true;
buttonSetWrongTextBox.Click += ButtonSetWrongTextBox_Click;
//
// buttonGetObject
//
buttonGetObject.Location = new Point(699, 463);
buttonGetObject.Name = "buttonGetObject";
buttonGetObject.Size = new Size(165, 29);
buttonGetObject.TabIndex = 9;
buttonGetObject.Text = "Получение объекта";
buttonGetObject.UseVisualStyleBackColor = true;
buttonGetObject.Click += ButtonGetObject_Click;
//
// buttonGetIndex
//
buttonGetIndex.Location = new Point(699, 516);
buttonGetIndex.Name = "buttonGetIndex";
buttonGetIndex.Size = new Size(165, 29);
buttonGetIndex.TabIndex = 10;
buttonGetIndex.Text = "Получение индекса";
buttonGetIndex.UseVisualStyleBackColor = true;
buttonGetIndex.Click += ButtonGetIndex_Click;
//
// buttonSetIndex
//
buttonSetIndex.Location = new Point(699, 569);
buttonSetIndex.Name = "buttonSetIndex";
buttonSetIndex.Size = new Size(165, 29);
buttonSetIndex.TabIndex = 11;
buttonSetIndex.Text = "Установка индекса";
buttonSetIndex.UseVisualStyleBackColor = true;
buttonSetIndex.Click += ButtonSetIndex_Click;
//
// FormTest
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(878, 787);
Controls.Add(buttonSetIndex);
Controls.Add(buttonGetIndex);
Controls.Add(buttonGetObject);
Controls.Add(buttonSetWrongTextBox);
Controls.Add(buttonSetTextBox);
Controls.Add(buttonGetTextBox);
Controls.Add(buttonSetComboBox);
Controls.Add(buttonGetComboBox);
Controls.Add(buttonClear);
Controls.Add(textBoxControl);
Controls.Add(listBoxControl);
Controls.Add(comboBoxControl);
Name = "FormTest";
Text = "FormTest";
ResumeLayout(false);
PerformLayout();
}
#endregion
private RodionovLibrary.VisualComponents.ComboBoxControl comboBoxControl;
private RodionovLibrary.VisualComponents.ListBoxControl listBoxControl;
private RodionovLibrary.VisualComponents.TextBoxControl textBoxControl;
private Button buttonClear;
private Button buttonGetComboBox;
private Button buttonSetComboBox;
private Button buttonGetTextBox;
private Button buttonSetTextBox;
private Button buttonSetWrongTextBox;
private Button buttonGetObject;
private Button buttonGetIndex;
private Button buttonSetIndex;
}
}

68
COP/WinForms/FormTest.cs Normal file
View File

@ -0,0 +1,68 @@
namespace WinForms
{
public partial class FormTest : Form
{
public FormTest()
{
InitializeComponent();
comboBoxControl.AddItems(new List<string> { "Çíà÷åíèå 1", "Çíà÷åíèå 2", "Çíà÷åíèå 3", "Çíà÷åíèå 4", "Çíà÷åíèå 5" });
textBoxControl.Pattern = @"^[a-z0-9._%+-]+\@([a-z0-9-]+\.)+[a-z]{2,4}$";
textBoxControl.SetTooltipText("example@gmail.com");
listBoxControl.SetParams("Èìÿ: {FirstName}, ôàìèëèÿ: {LastName}. {Gender} ({Age}) ëåò.", '{', '}');
listBoxControl.AddItems(new List<Person> { new() { FirstName = "Êèðèëë", LastName = "Ïåòðîâ", Age = 23, Gender = "ìóæ" },
new() { FirstName = "Ìàðèÿ", LastName = "Èâàíîâà", Age = 18, Gender = "æåí" },
new() { FirstName = "Åâà", LastName = "Ïàíôèëîâà", Age = 40, Gender = "æåí" } });
}
private void ButtonClear_Click(object sender, EventArgs e)
{
comboBoxControl.Clear();
}
private void ButtonGetComboBox_Click(object sender, EventArgs e)
{
MessageBox.Show(comboBoxControl.SelectedValue, "Ïîëó÷åííîå çíà÷åíèå");
}
private void ButtonSetComboBox_Click(object sender, EventArgs e)
{
comboBoxControl.SelectedValue = "Çíà÷åíèå 3";
}
private void ButtonGetTextBox_Click(object sender, EventArgs e)
{
MessageBox.Show(textBoxControl.Value, "Ïîëó÷åííîå çíà÷åíèå");
}
private void ButtonSetTextBox_Click(object sender, EventArgs e)
{
textBoxControl.Value = "forum98761@gmail.com";
}
private void ButtonSetWrongTextBox_Click(object sender, EventArgs e)
{
textBoxControl.Value = "smth";
}
private void ButtonGetObject_Click(object sender, EventArgs e)
{
Person? selectedPerson = listBoxControl.GetObject<Person>();
if (selectedPerson == null)
MessageBox.Show("Îáüåêò ïóñòîé");
MessageBox.Show($"Èìÿ: {selectedPerson?.FirstName}, Ôàìèëèÿ: {selectedPerson?.LastName}, " +
$"Âîçðàñò: {selectedPerson?.Age}, Ïîë: {selectedPerson?.Gender}");
}
private void ButtonGetIndex_Click(object sender, EventArgs e)
{
MessageBox.Show(listBoxControl.SelectedIndex.ToString(), "Ïîëó÷åííîå çíà÷åíèå");
}
private void ButtonSetIndex_Click(object sender, EventArgs e)
{
listBoxControl.SelectedIndex = 0;
}
}
}

120
COP/WinForms/FormTest.resx Normal file
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>

13
COP/WinForms/Person.cs Normal file
View File

@ -0,0 +1,13 @@
namespace WinForms
{
public class Person
{
public string FirstName { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
public int Age { get; set; }
public string Gender { get; set; } = string.Empty;
}
}

View File

@ -11,7 +11,7 @@ namespace WinForms
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
Application.Run(new FormTest());
}
}
}

View File

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