Compare commits

...

6 Commits
main ... Lab1

19 changed files with 1178 additions and 81 deletions

View File

@ -1,6 +0,0 @@
namespace Controls
{
public class Class1
{
}
}

View File

@ -0,0 +1,56 @@
namespace Controls
{
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()
{
comboBoxMain = new ComboBox();
SuspendLayout();
//
// comboBoxMain
//
comboBoxMain.FormattingEnabled = true;
comboBoxMain.Location = new Point(18, 62);
comboBoxMain.Name = "comboBoxMain";
comboBoxMain.Size = new Size(230, 28);
comboBoxMain.TabIndex = 0;
//
// CustomComboBox
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(comboBoxMain);
Name = "CustomComboBox";
Size = new Size(262, 150);
ResumeLayout(false);
}
#endregion
private ComboBox comboBoxMain;
}
}

View File

@ -0,0 +1,95 @@
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 Controls
{
public partial class CustomComboBox : UserControl
{
/// <summary>
/// Конструктор
/// </summary>
public CustomComboBox()
{
InitializeComponent();
}
/// <summary>
/// Очищение списка
/// </summary>
public void ComboBoxClear()
{
comboBoxMain.Items.Clear();
comboBoxMain.SelectedItem = null;
}
/// <summary>
/// Выбранный элемент
/// </summary>
public string SelectedItem
{
get
{
if (comboBoxMain.Items.Count == 0)
{
return " ";
}
if (comboBoxMain.SelectedItem == null)
{
return " ";
}
return comboBoxMain.SelectedItem.ToString()!;
}
set
{
if (comboBoxMain.Items.Contains(value))
{
comboBoxMain.SelectedItem = value;
}
}
}
/// <summary>
/// Публичное свойство
/// </summary>
public ComboBox.ObjectCollection ComboBoxItems
{
get { return comboBoxMain.Items; }
}
/// <summary>
/// Событие, вызываемое при смене значения
/// </summary>
private EventHandler _onValueChangedEvent;
/// <summary>
/// Событие, вызываемое при смене значения
/// </summary>
public event EventHandler ValueChanged
{
add
{
_onValueChangedEvent += value;
}
remove
{
_onValueChangedEvent -= value;
}
}
/// <summary>
/// Смена значения
/// </summary>
private void CustomComboBox_SelectedValueChanged(object sender, EventArgs e)
{
_onValueChangedEvent?.Invoke(sender, e);
}
}
}

View File

@ -1,17 +1,17 @@
<?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
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>
@ -26,36 +26,36 @@
<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
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
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
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
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
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
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
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->

View File

@ -0,0 +1,58 @@
namespace Controls
{
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()
{
listBoxMain = new ListBox();
SuspendLayout();
//
// listBoxMain
//
listBoxMain.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
listBoxMain.FormattingEnabled = true;
listBoxMain.ItemHeight = 20;
listBoxMain.Location = new Point(3, 3);
listBoxMain.Name = "listBoxMain";
listBoxMain.Size = new Size(270, 184);
listBoxMain.TabIndex = 0;
//
// CustomListBox
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(listBoxMain);
Name = "CustomListBox";
Size = new Size(276, 212);
ResumeLayout(false);
}
#endregion
private ListBox listBoxMain;
}
}

View File

@ -0,0 +1,132 @@
using Controls.Exceptions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Controls
{
public partial class CustomListBox : UserControl
{
/// <summary>
/// Конструктор по умолчанию
/// </summary>
public CustomListBox()
{
InitializeComponent();
}
/// <summary>
/// Макет
/// </summary>
private string _templateString;
/// <summary>
/// Символ начала
/// </summary>
private string _startSymbol;
/// <summary>
/// Символ конца
/// </summary>
private string _endSymbol;
/// <summary>
/// Шаблон строки
/// </summary>
public void SetTemplateString(string templateString, string startSymbol, string endSymbol)
{
if (templateString != "" && startSymbol != "" && endSymbol != "")
{
_templateString = templateString;
_startSymbol = startSymbol;
_endSymbol = endSymbol;
}
else
{
throw new ArgumentNullException("Вы не ввели все значения");
}
}
/// <summary>
/// Выбранная строка
/// </summary>
public int SelectedIndex
{
get { return listBoxMain.SelectedIndex; }
set
{
if (listBoxMain.SelectedIndex != 0)
{
listBoxMain.SelectedIndex = value;
}
}
}
/// <summary>
/// Получение обхекта
/// </summary>
public T GetObjectFromStr<T>() where T : class, new()
{
if (listBoxMain.SelectedIndex == -1)
{
return null;
}
string row = listBoxMain.SelectedItem.ToString();
T curObject = new T();
StringBuilder sb = new StringBuilder(row);
foreach (var property in typeof(T).GetProperties())
{
if (!property.CanWrite)
{
continue;
}
int borderOne = sb.ToString().IndexOf(_startSymbol);
if (borderOne == -1)
{
break;
}
int borderTwo = sb.ToString().IndexOf(_endSymbol, borderOne + 1);
if (borderTwo == -1)
{
break;
}
string propertyValue = sb.ToString(borderOne + 1, borderTwo - borderOne - 1);
sb.Remove(0, borderTwo + 1);
property.SetValue(curObject, Convert.ChangeType(propertyValue, property.PropertyType));
}
return curObject;
}
/// <summary>
/// Заполнение
/// </summary>
public void FillProperty<T>(T dataObject, int rowIndex, string propertyName)
{
while (listBoxMain.Items.Count <= rowIndex)
{
listBoxMain.Items.Add(_templateString);
}
string row = listBoxMain.Items[rowIndex].ToString();
PropertyInfo propertyInfo = dataObject.GetType().GetProperty(propertyName);
if (propertyInfo != null)
{
object propertyValue = propertyInfo.GetValue(dataObject);
row = row.Replace($"{_startSymbol}{propertyName}{_endSymbol}", propertyValue.ToString());
listBoxMain.Items[rowIndex] = row;
}
}
}
}

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,62 @@
namespace Controls
{
partial class CustomTextBoxNumber
{
/// <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();
textBoxNumber = new TextBox();
toolTipNumber = new ToolTip(components);
SuspendLayout();
//
// textBoxNumber
//
textBoxNumber.Location = new Point(25, 61);
textBoxNumber.Name = "textBoxNumber";
textBoxNumber.Size = new Size(213, 27);
textBoxNumber.TabIndex = 0;
toolTipNumber.SetToolTip(textBoxNumber, "+79378811555");
textBoxNumber.Click += textBox_Enter;
textBoxNumber.Text = "+79991144333";
//
// CustomNumberBox
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(textBoxNumber);
Name = "CustomNumberBox";
Size = new Size(264, 150);
ResumeLayout(false);
PerformLayout();
}
#endregion
private TextBox textBoxNumber;
private ToolTip toolTipNumber;
}
}

View File

@ -0,0 +1,111 @@
using Controls.Exceptions;
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;
namespace Controls
{
public partial class CustomTextBoxNumber : UserControl
{
/// <summary>
/// Конструктор
/// </summary>
public CustomTextBoxNumber()
{
InitializeComponent();
}
/// <summary>
/// Шаблон вводимого значения
/// </summary>
private string? _numberPattern;
/// <summary>
/// Шаблон вводимого значения
/// </summary>
public string? NumPattern
{
get { return _numberPattern; }
set { _numberPattern = value; }
}
/// <summary>
/// Введенное значение
/// </summary>
public string? TextBoxNumber
{
get
{
if (NumPattern == null)
{
throw new CustomNumberException("Шаблон не заполнен!");
}
Regex regex = new Regex(NumPattern);
if (regex.IsMatch(textBoxNumber.Text))
{
return textBoxNumber.Text;
}
else
{
throw new CustomNumberException(textBoxNumber.Text + " не соответствует шаблону!");
}
}
set
{
Regex regex = new Regex(NumPattern!);
if (regex.IsMatch(value))
{
textBoxNumber.Text = value;
}
}
}
/// <summary>
/// Событие, вызываемое при смене значения
/// </summary>
private EventHandler _onValueChangedEvent;
/// <summary>
/// Событие, вызываемое при смене значения
/// </summary>
public event EventHandler ValueChanged
{
add
{
_onValueChangedEvent += value;
}
remove
{
_onValueChangedEvent -= value;
}
}
/// <summary>
/// Смена значения
/// </summary>
private void CustomNumberBox_NumberChanged(object sender, EventArgs e)
{
_onValueChangedEvent?.Invoke(sender, e);
}
/// <summary>
/// Выведение подсказки на экран
/// </summary>
private void textBox_Enter(object sender, EventArgs e)
{
int visibleTime = 2000;
ToolTip tooltip = new ToolTip();
tooltip.Show("+79991144333", textBoxNumber, 30, -20, visibleTime);
}
}
}

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="toolTipNumber.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Controls.Exceptions
{
public class CustomNumberException : Exception
{
/// <summary>
/// Конструктор по умолчанию
/// </summary>
public CustomNumberException() { }
/// <summary>
/// Конструктор с сообщением ошибки
/// </summary>
public CustomNumberException(string message) : base(message)
{
}
}
}

View File

@ -1,39 +0,0 @@
namespace Forms
{
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 Forms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

162
Cop_25/Forms/FormMain.Designer.cs generated Normal file
View File

@ -0,0 +1,162 @@
namespace Forms
{
partial class FormMain
{
/// <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()
{
components = new System.ComponentModel.Container();
customTextBoxNumber = new Controls.CustomTextBoxNumber();
customComboBox = new Controls.CustomComboBox();
labelNum = new Label();
labelCombo = new Label();
labelList = new Label();
customListBox = new Controls.CustomListBox();
buttonValidate = new Button();
buttonGetBro = new Button();
toolTip = new ToolTip(components);
button1 = new Button();
SuspendLayout();
//
// customTextBoxNumber
//
customTextBoxNumber.Location = new Point(2, 187);
customTextBoxNumber.Name = "customTextBoxNumber";
customTextBoxNumber.NumPattern = null;
customTextBoxNumber.Size = new Size(261, 105);
customTextBoxNumber.TabIndex = 0;
//
// customComboBox
//
customComboBox.Location = new Point(2, 19);
customComboBox.Name = "customComboBox";
customComboBox.SelectedItem = " ";
customComboBox.Size = new Size(301, 188);
customComboBox.TabIndex = 1;
//
// labelNum
//
labelNum.AutoSize = true;
labelNum.Location = new Point(68, 187);
labelNum.Name = "labelNum";
labelNum.Size = new Size(130, 20);
labelNum.TabIndex = 2;
labelNum.Text = "Номер телефона:";
//
// labelCombo
//
labelCombo.AutoSize = true;
labelCombo.Location = new Point(88, 42);
labelCombo.Name = "labelCombo";
labelCombo.Size = new Size(95, 20);
labelCombo.TabIndex = 3;
labelCombo.Text = "Комбо бокс:";
//
// labelList
//
labelList.AutoSize = true;
labelList.Location = new Point(509, 19);
labelList.Name = "labelList";
labelList.Size = new Size(59, 20);
labelList.TabIndex = 4;
labelList.Text = "Спсиок";
//
// customListBox
//
customListBox.Location = new Point(334, 42);
customListBox.Name = "customListBox";
customListBox.SelectedIndex = -1;
customListBox.Size = new Size(454, 250);
customListBox.TabIndex = 5;
//
// buttonValidate
//
buttonValidate.Location = new Point(22, 298);
buttonValidate.Name = "buttonValidate";
buttonValidate.Size = new Size(215, 29);
buttonValidate.TabIndex = 6;
buttonValidate.Text = "проверка телефона";
buttonValidate.UseVisualStyleBackColor = true;
buttonValidate.Click += buttonValidate_Click;
//
// buttonGetBro
//
buttonGetBro.Location = new Point(334, 263);
buttonGetBro.Name = "buttonGetBro";
buttonGetBro.Size = new Size(273, 29);
buttonGetBro.TabIndex = 7;
buttonGetBro.Text = "получить друга";
buttonGetBro.UseVisualStyleBackColor = true;
buttonGetBro.Click += buttonGetObject_Click;
//
// toolTip
//
toolTip.ToolTipTitle = "AAAA";
//
// button1
//
button1.Location = new Point(22, 119);
button1.Name = "button1";
button1.Size = new Size(94, 29);
button1.TabIndex = 8;
button1.Text = "добавить";
button1.UseVisualStyleBackColor = true;
button1.Click += buttonAdd_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(button1);
Controls.Add(buttonGetBro);
Controls.Add(buttonValidate);
Controls.Add(customListBox);
Controls.Add(labelList);
Controls.Add(labelCombo);
Controls.Add(labelNum);
Controls.Add(customComboBox);
Controls.Add(customTextBoxNumber);
Name = "FormMain";
Text = "FormMain";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Controls.CustomTextBoxNumber customTextBoxNumber;
private Controls.CustomComboBox customComboBox;
private Label labelNum;
private Label labelCombo;
private Label labelList;
private Controls.CustomListBox customListBox;
private Button buttonValidate;
private Button buttonGetBro;
private ToolTip toolTip;
private Button button1;
}
}

68
Cop_25/Forms/FormMain.cs Normal file
View File

@ -0,0 +1,68 @@
using Controls;
using Controls.Exceptions;
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 Forms
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
customComboBox.ComboBoxItems.Add("aboba1");
customComboBox.ComboBoxItems.Add("aboba2");
customComboBox.SelectedItem = "aboba1";
customTextBoxNumber.NumPattern = @"^\+7\d{10}$";
customListBox.SetTemplateString("Имя: {FirstName}, Фамилия: {LastName}, Возраст: {Age}", "{", "}");
Person person1 = new Person { FirstName = "{Лена}", LastName = "{Пряникова}", Age = "{18}" };
Person person2 = new Person { FirstName = "{Сергей}", LastName = "{Конфеткович}", Age = "{20}" };
customListBox.FillProperty(person1, 0, "FirstName");
customListBox.FillProperty(person1, 0, "LastName");
customListBox.FillProperty(person1, 0, "Age");
customListBox.FillProperty(person2, 1, "FirstName");
customListBox.FillProperty(person2, 1, "LastName");
customListBox.FillProperty(person2, 1, "Age");
}
private void buttonValidate_Click(object sender, EventArgs e)
{
try
{
string phoneNumber = customTextBoxNumber.TextBoxNumber;
MessageBox.Show($"Введенный номер: {phoneNumber}");
}
catch (CustomNumberException ex)
{
MessageBox.Show($"Ошибка: {ex.Message}");
}
}
private void buttonGetObject_Click(object sender, EventArgs e)
{
try
{
Person selectedPerson = customListBox.GetObjectFromStr<Person>();
MessageBox.Show($"Ваш друг. Имя: {selectedPerson.FirstName}, Фамилия: {selectedPerson.LastName}, Возраст: {selectedPerson.Age}");
}
catch (Exception ex)
{
MessageBox.Show($"Ошибка: {ex.Message}");
}
}
private void buttonAdd_Click(object sender, EventArgs e)
{
customComboBox.ComboBoxItems.Add("abobaSECRET");
}
}
}

123
Cop_25/Forms/FormMain.resx Normal file
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

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

15
Cop_25/Forms/Person.cs Normal file
View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Forms
{
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Age { get; set; }
}
}

View File

@ -11,7 +11,7 @@ namespace Forms
// 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 FormMain());
}
}
}