Сданная 1 лаба
This commit is contained in:
parent
6c7d068a8d
commit
79a329d782
@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.33424.131
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinForm", "WinForm\WinForm.csproj", "{79A863DB-93E6-44C2-AB0F-DE0D19BE72DC}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinForm", "WinForm\WinForm.csproj", "{79A863DB-93E6-44C2-AB0F-DE0D19BE72DC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsLibrary", "WinFormsLibrary\WinFormsLibrary.csproj", "{B617E65D-B482-4120-BC74-66B760D66FEF}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -15,6 +17,10 @@ Global
|
||||
{79A863DB-93E6-44C2-AB0F-DE0D19BE72DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{79A863DB-93E6-44C2-AB0F-DE0D19BE72DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{79A863DB-93E6-44C2-AB0F-DE0D19BE72DC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B617E65D-B482-4120-BC74-66B760D66FEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B617E65D-B482-4120-BC74-66B760D66FEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B617E65D-B482-4120-BC74-66B760D66FEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B617E65D-B482-4120-BC74-66B760D66FEF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
71
WinForm/WinFormsLibrary/DropDownList.Designer.cs
generated
Normal file
71
WinForm/WinFormsLibrary/DropDownList.Designer.cs
generated
Normal file
@ -0,0 +1,71 @@
|
||||
namespace WinForm
|
||||
{
|
||||
partial class DropDownList
|
||||
{
|
||||
/// <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();
|
||||
labelTitle = new Label();
|
||||
SuspendLayout();
|
||||
//
|
||||
// comboBox
|
||||
//
|
||||
comboBox.FormattingEnabled = true;
|
||||
comboBox.Location = new Point(13, 39);
|
||||
comboBox.Name = "comboBox";
|
||||
comboBox.Size = new Size(232, 23);
|
||||
comboBox.TabIndex = 0;
|
||||
comboBox.SelectedValueChanged += ComboBox_SelectedValueChanged;
|
||||
//
|
||||
// labelTitle
|
||||
//
|
||||
labelTitle.AutoSize = true;
|
||||
labelTitle.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point);
|
||||
labelTitle.Location = new Point(13, 11);
|
||||
labelTitle.Name = "labelTitle";
|
||||
labelTitle.Size = new Size(133, 15);
|
||||
labelTitle.TabIndex = 1;
|
||||
labelTitle.Text = "Выпадающий список";
|
||||
//
|
||||
// DropDownList
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(labelTitle);
|
||||
Controls.Add(comboBox);
|
||||
Name = "DropDownList";
|
||||
Size = new Size(260, 80);
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox comboBox;
|
||||
private Label labelTitle;
|
||||
}
|
||||
}
|
72
WinForm/WinFormsLibrary/DropDownList.cs
Normal file
72
WinForm/WinFormsLibrary/DropDownList.cs
Normal file
@ -0,0 +1,72 @@
|
||||
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 WinForm
|
||||
{
|
||||
public partial class DropDownList : UserControl
|
||||
{
|
||||
public DropDownList()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
comboBox.Items.Clear();
|
||||
}
|
||||
|
||||
public string Selected
|
||||
{
|
||||
get
|
||||
{
|
||||
if (comboBox.Items.Count == 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
if (comboBox.SelectedItem == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return comboBox.SelectedItem.ToString()!;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (comboBox.Items.Contains(value))
|
||||
{
|
||||
comboBox.SelectedItem = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public ComboBox.ObjectCollection ComboBoxItems
|
||||
{
|
||||
get { return comboBox.Items; }
|
||||
}
|
||||
|
||||
private EventHandler _explicitEvent;
|
||||
public event EventHandler ExplicitEvent
|
||||
{
|
||||
add
|
||||
{
|
||||
_explicitEvent += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_explicitEvent -= value;
|
||||
}
|
||||
}
|
||||
|
||||
private void ComboBox_SelectedValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
_explicitEvent?.Invoke(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
60
WinForm/WinFormsLibrary/DropDownList.resx
Normal file
60
WinForm/WinFormsLibrary/DropDownList.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<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>
|
71
WinForm/WinFormsLibrary/ListBoxValues.Designer.cs
generated
Normal file
71
WinForm/WinFormsLibrary/ListBoxValues.Designer.cs
generated
Normal file
@ -0,0 +1,71 @@
|
||||
namespace WinForm
|
||||
{
|
||||
partial class ListBoxValues
|
||||
{
|
||||
/// <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();
|
||||
componentTitleLabel = new Label();
|
||||
SuspendLayout();
|
||||
//
|
||||
// listBox
|
||||
//
|
||||
listBox.FormattingEnabled = true;
|
||||
listBox.ItemHeight = 15;
|
||||
listBox.Location = new Point(12, 39);
|
||||
listBox.Name = "listBox";
|
||||
listBox.Size = new Size(172, 154);
|
||||
listBox.TabIndex = 0;
|
||||
//
|
||||
// componentTitleLabel
|
||||
//
|
||||
componentTitleLabel.AutoSize = true;
|
||||
componentTitleLabel.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point);
|
||||
componentTitleLabel.Location = new Point(12, 12);
|
||||
componentTitleLabel.Name = "componentTitleLabel";
|
||||
componentTitleLabel.Size = new Size(108, 15);
|
||||
componentTitleLabel.TabIndex = 1;
|
||||
componentTitleLabel.Text = "Список занчений";
|
||||
//
|
||||
// ListBoxValues
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(componentTitleLabel);
|
||||
Controls.Add(listBox);
|
||||
Name = "ListBoxValues";
|
||||
Size = new Size(200, 206);
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ListBox listBox;
|
||||
private Label componentTitleLabel;
|
||||
}
|
||||
}
|
113
WinForm/WinFormsLibrary/ListBoxValues.cs
Normal file
113
WinForm/WinFormsLibrary/ListBoxValues.cs
Normal file
@ -0,0 +1,113 @@
|
||||
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 WinForm
|
||||
{
|
||||
public partial class ListBoxValues : UserControl
|
||||
{
|
||||
private string layoutString;
|
||||
private string startSymbol;
|
||||
private string endSymbol;
|
||||
|
||||
public ListBoxValues()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void SetLayoutInfo(string layout, string startS, string endS)
|
||||
{
|
||||
if (layout == null || startS == null || endS == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
layoutString = layout;
|
||||
startSymbol = startS;
|
||||
endSymbol = endS;
|
||||
}
|
||||
|
||||
public int SelectedIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
if (listBox.SelectedIndex == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return listBox.SelectedIndex;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (listBox.SelectedItems.Count != 0)
|
||||
{
|
||||
listBox.SelectedIndex = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T GetObjectFromStr<T>() where T : class, new()
|
||||
{
|
||||
if (listBox.SelectedIndex == -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string row = listBox.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;
|
||||
}
|
||||
|
||||
public void FillProperty<T>(T dataObject, int rowIndex, string propertyName)
|
||||
{
|
||||
if (layoutString == null || startSymbol == null || endSymbol == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (listBox.Items.Count <= rowIndex)
|
||||
{
|
||||
listBox.Items.Add(layoutString);
|
||||
}
|
||||
|
||||
string row = listBox.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());
|
||||
listBox.Items[rowIndex] = row;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
WinForm/WinFormsLibrary/ListBoxValues.resx
Normal file
60
WinForm/WinFormsLibrary/ListBoxValues.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<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>
|
72
WinForm/WinFormsLibrary/NumberTextBox.Designer.cs
generated
Normal file
72
WinForm/WinFormsLibrary/NumberTextBox.Designer.cs
generated
Normal file
@ -0,0 +1,72 @@
|
||||
namespace WinForm
|
||||
{
|
||||
partial class NumberTextBox
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
componentTitleLabel = new Label();
|
||||
textBox = new TextBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// componentTitleLabel
|
||||
//
|
||||
componentTitleLabel.AutoSize = true;
|
||||
componentTitleLabel.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point);
|
||||
componentTitleLabel.Location = new Point(13, 12);
|
||||
componentTitleLabel.Name = "componentTitleLabel";
|
||||
componentTitleLabel.Size = new Size(154, 15);
|
||||
componentTitleLabel.TabIndex = 1;
|
||||
componentTitleLabel.Text = "Введите номер телефона";
|
||||
//
|
||||
// textBox
|
||||
//
|
||||
textBox.Location = new Point(13, 41);
|
||||
textBox.Name = "textBox";
|
||||
textBox.Size = new Size(234, 23);
|
||||
textBox.TabIndex = 2;
|
||||
textBox.TextChanged += TextBox_TextChanged;
|
||||
textBox.Enter += TextBox_Enter;
|
||||
//
|
||||
// NumberTextBox
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(textBox);
|
||||
Controls.Add(componentTitleLabel);
|
||||
Name = "NumberTextBox";
|
||||
Size = new Size(260, 80);
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private TextBox numberTextBox;
|
||||
private Label componentTitleLabel;
|
||||
private TextBox textBox;
|
||||
}
|
||||
}
|
86
WinForm/WinFormsLibrary/NumberTextBox.cs
Normal file
86
WinForm/WinFormsLibrary/NumberTextBox.cs
Normal file
@ -0,0 +1,86 @@
|
||||
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 WinForm
|
||||
{
|
||||
public partial class NumberTextBox : UserControl
|
||||
{
|
||||
//Шаблон для textbox
|
||||
private string? pattern;
|
||||
private string example = "+7XXXXXXXXXX";
|
||||
|
||||
public NumberTextBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
//Публичное свойство для получения и заполнения шаблона
|
||||
public string? Pattern
|
||||
{
|
||||
get { return pattern; }
|
||||
set { pattern = value; }
|
||||
}
|
||||
|
||||
public string? TextBoxValue
|
||||
{
|
||||
get
|
||||
{
|
||||
if (new Regex(Pattern).IsMatch(textBox.Text))
|
||||
{
|
||||
return textBox.Text;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (new Regex(Pattern).IsMatch(value))
|
||||
{
|
||||
textBox.Text = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Метод для заполнения примера
|
||||
public void SetExample(string str)
|
||||
{
|
||||
if (new Regex(Pattern).IsMatch(str))
|
||||
{
|
||||
example = str;
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBox_Enter(object sender, EventArgs e)
|
||||
{
|
||||
int VisibleTime = 3000;
|
||||
ToolTip tt = new ToolTip();
|
||||
tt.Show(example, textBox, 0, 25, VisibleTime);
|
||||
}
|
||||
|
||||
private EventHandler _explicitEvent;
|
||||
public event EventHandler ExplicitEvent
|
||||
{
|
||||
add
|
||||
{
|
||||
_explicitEvent += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_explicitEvent -= value;
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBox_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
_explicitEvent?.Invoke(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
60
WinForm/WinFormsLibrary/NumberTextBox.resx
Normal file
60
WinForm/WinFormsLibrary/NumberTextBox.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<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>
|
Loading…
Reference in New Issue
Block a user