ну че то пошаманила
This commit is contained in:
parent
d094847a13
commit
c4bb4272c6
2
COP_7/DropDownList.Designer.cs
generated
2
COP_7/DropDownList.Designer.cs
generated
@ -1,4 +1,4 @@
|
|||||||
namespace COP_7
|
namespace Components
|
||||||
{
|
{
|
||||||
partial class DropDownList
|
partial class DropDownList
|
||||||
{
|
{
|
||||||
|
@ -8,39 +8,28 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace COP_7
|
namespace Components
|
||||||
{
|
{
|
||||||
public partial class DropDownList : UserControl
|
public partial class DropDownList : UserControl
|
||||||
{
|
{
|
||||||
|
|
||||||
public ComboBox.ObjectCollection Items => ComboBox.Items;
|
|
||||||
|
|
||||||
public event EventHandler _сhangeEvent;
|
|
||||||
|
|
||||||
public event EventHandler ChangeEvent
|
|
||||||
{
|
|
||||||
add
|
|
||||||
{
|
|
||||||
_сhangeEvent += value;
|
|
||||||
}
|
|
||||||
remove
|
|
||||||
{
|
|
||||||
_сhangeEvent -= value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public DropDownList()
|
public DropDownList()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string SelectedValue
|
public string SelectedItem
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return ComboBox.Items.Contains(ComboBox.SelectedItem) ? ComboBox.SelectedItem?.ToString() ?? "" : "";
|
if (ComboBox.Items.Count == 0)
|
||||||
|
{
|
||||||
|
return " ";
|
||||||
|
}
|
||||||
|
if (ComboBox.SelectedItem == null)
|
||||||
|
{
|
||||||
|
return " ";
|
||||||
|
}
|
||||||
|
return ComboBox.SelectedItem.ToString()!;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
@ -48,21 +37,41 @@ namespace COP_7
|
|||||||
{
|
{
|
||||||
ComboBox.SelectedItem = value;
|
ComboBox.SelectedItem = value;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
ComboBox.SelectedIndex = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clear()
|
|
||||||
|
public ComboBox.ObjectCollection ComboBoxItems
|
||||||
{
|
{
|
||||||
Items.Clear();
|
get { return ComboBox.Items; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
||||||
|
private EventHandler _onValueChangedEvent;
|
||||||
|
|
||||||
|
public event EventHandler ValueChanged
|
||||||
{
|
{
|
||||||
_сhangeEvent?.Invoke(this, e);
|
add
|
||||||
|
{
|
||||||
|
_onValueChangedEvent += value;
|
||||||
|
}
|
||||||
|
|
||||||
|
remove
|
||||||
|
{
|
||||||
|
_onValueChangedEvent -= value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CustomComboBox_SelectedValueChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_onValueChangedEvent?.Invoke(sender, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ComboBoxClear()
|
||||||
|
{
|
||||||
|
ComboBox.Items.Clear();
|
||||||
|
ComboBox.SelectedItem = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
20
COP_7/Exceptions/PhoneException.cs
Normal file
20
COP_7/Exceptions/PhoneException.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Components.Exceptions
|
||||||
|
{
|
||||||
|
public class PhoneException : Exception
|
||||||
|
{
|
||||||
|
public PhoneException() { }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор с сообщением ошибки
|
||||||
|
/// </summary>
|
||||||
|
public PhoneException(string message) : base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
35
COP_7/ListBoxMany.Designer.cs
generated
35
COP_7/ListBoxMany.Designer.cs
generated
@ -1,4 +1,4 @@
|
|||||||
namespace CustomComponent
|
namespace Components
|
||||||
{
|
{
|
||||||
partial class ListBoxMany
|
partial class ListBoxMany
|
||||||
{
|
{
|
||||||
@ -28,30 +28,27 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.listBox = new System.Windows.Forms.ListBox();
|
listBox = new ListBox();
|
||||||
this.SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// listBox
|
// listBox
|
||||||
//
|
//
|
||||||
this.listBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
listBox.FormattingEnabled = true;
|
||||||
| System.Windows.Forms.AnchorStyles.Left)
|
listBox.ItemHeight = 20;
|
||||||
| System.Windows.Forms.AnchorStyles.Right)));
|
listBox.Location = new Point(20, 18);
|
||||||
this.listBox.FormattingEnabled = true;
|
listBox.Margin = new Padding(3, 4, 3, 4);
|
||||||
this.listBox.ItemHeight = 15;
|
listBox.Name = "listBox";
|
||||||
this.listBox.Location = new System.Drawing.Point(0, 0);
|
listBox.Size = new Size(244, 264);
|
||||||
this.listBox.Name = "listBox";
|
listBox.TabIndex = 0;
|
||||||
this.listBox.Size = new System.Drawing.Size(300, 300);
|
|
||||||
this.listBox.TabIndex = 0;
|
|
||||||
//
|
//
|
||||||
// ListBoxMany
|
// ListBoxMany
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
AutoScaleMode = AutoScaleMode.None;
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
Controls.Add(listBox);
|
||||||
this.Controls.Add(this.listBox);
|
Margin = new Padding(3, 4, 3, 4);
|
||||||
this.Name = "ListBoxMany";
|
Name = "ListBoxMany";
|
||||||
this.Size = new System.Drawing.Size(300, 300);
|
Size = new Size(284, 306);
|
||||||
this.ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -4,105 +4,128 @@ using System.ComponentModel;
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace CustomComponent
|
namespace Components
|
||||||
{
|
{
|
||||||
public partial class ListBoxMany : UserControl
|
public partial class ListBoxMany : UserControl
|
||||||
{
|
{
|
||||||
private string LayoutString;
|
/// <summary>
|
||||||
private string StartS;
|
/// Конструктор по умолчанию
|
||||||
private string EndS;
|
/// </summary>
|
||||||
private int SelectedStr;
|
|
||||||
|
|
||||||
public ListBoxMany()
|
public ListBoxMany()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
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
|
public int SelectedIndex
|
||||||
{
|
{
|
||||||
get
|
get { return listBox.SelectedIndex; }
|
||||||
{
|
|
||||||
if (listBox.SelectedIndex == -1)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return listBox.SelectedIndex;
|
|
||||||
}
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (listBox.Items.Count != 0)
|
if (listBox.SelectedIndex != 0)
|
||||||
{
|
{
|
||||||
listBox.SelectedIndex = value;
|
listBox.SelectedIndex = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void SetLayout(string layoutString, string startS, string endS)
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение обхекта
|
||||||
|
/// </summary>
|
||||||
|
public T GetObjectFromStr<T>() where T : class, new()
|
||||||
{
|
{
|
||||||
if (layoutString == null || startS == null || endS == null) return;
|
if (listBox.SelectedIndex == -1)
|
||||||
LayoutString = layoutString;
|
{
|
||||||
StartS = startS;
|
return null;
|
||||||
EndS = endS;
|
|
||||||
}
|
}
|
||||||
public void AddItemInList<T>(T Object, int rowIndex, int columnIndex)
|
string row = listBox.SelectedItem.ToString();
|
||||||
|
T curObject = new T();
|
||||||
|
StringBuilder sb = new StringBuilder(row);
|
||||||
|
foreach (var property in typeof(T).GetProperties())
|
||||||
{
|
{
|
||||||
if (Object == null)
|
if (!property.CanWrite)
|
||||||
{
|
|
||||||
throw new ArgumentNullException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (listBox.Items.Count <= rowIndex)
|
|
||||||
{
|
|
||||||
for (int i = listBox.Items.Count; i <= rowIndex; i++)
|
|
||||||
{
|
|
||||||
listBox.Items.Add(LayoutString);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
string str = listBox.Items[rowIndex].ToString();
|
|
||||||
|
|
||||||
var properties = Object.GetType().GetProperties();
|
|
||||||
if (columnIndex < properties.Length)
|
|
||||||
{
|
|
||||||
var prop = properties[columnIndex];
|
|
||||||
string str1 = $"{StartS}{prop.Name}{EndS}";
|
|
||||||
str = str.Replace(str1, prop.GetValue(Object)?.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
listBox.Items[rowIndex] = str;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public T GetItemFromList<T>() where T : class, new()
|
|
||||||
{
|
|
||||||
string SelectedStr = "";
|
|
||||||
if (listBox.SelectedIndex != -1)
|
|
||||||
{
|
|
||||||
SelectedStr = listBox.SelectedItem.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
T currentObject = new T();
|
|
||||||
|
|
||||||
foreach (var prop in typeof(T).GetProperties())
|
|
||||||
{
|
|
||||||
if (!prop.CanWrite)
|
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int startS = SelectedStr.IndexOf(StartS);
|
|
||||||
int endS = SelectedStr.IndexOf(EndS);
|
int borderOne = sb.ToString().IndexOf(_startSymbol);
|
||||||
if (startS == -1 || endS == -1)
|
if (borderOne == -1)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
string propValue = SelectedStr.Substring(startS + 1, endS - startS - 1);
|
|
||||||
SelectedStr = SelectedStr.Substring(endS + 1);
|
int borderTwo = sb.ToString().IndexOf(_endSymbol, borderOne + 1);
|
||||||
prop.SetValue(currentObject, Convert.ChangeType(propValue, prop.PropertyType));
|
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 (listBox.Items.Count <= rowIndex)
|
||||||
|
{
|
||||||
|
listBox.Items.Add(_templateString);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
return currentObject;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,64 @@
|
|||||||
<root>
|
<?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: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:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
@ -1,100 +0,0 @@
|
|||||||
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;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace CustomComponent
|
|
||||||
{
|
|
||||||
public partial class PhoneTextBox : UserControl
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
private string? pattern;
|
|
||||||
private string example = "+7(XXX)XXX-XX-XX";
|
|
||||||
public PhoneTextBox()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public string? Pattern
|
|
||||||
{
|
|
||||||
get { return pattern; }
|
|
||||||
set { pattern = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public string TextBoxValue
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
Regex regex = new Regex(Pattern);
|
|
||||||
bool isValid = regex.IsMatch(textBox.Text);
|
|
||||||
if (isValid)
|
|
||||||
{
|
|
||||||
return textBox.Text;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Error = "Неправильный ввод";
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
Regex regex = new Regex(Pattern);
|
|
||||||
bool isValid = regex.IsMatch(value);
|
|
||||||
if (isValid)
|
|
||||||
{
|
|
||||||
textBox.Text = value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Error = "Неправильно";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Error
|
|
||||||
{
|
|
||||||
get; private set;
|
|
||||||
}
|
|
||||||
public void SetExample(string exampleStr)
|
|
||||||
{
|
|
||||||
Regex regex = new Regex(Pattern);
|
|
||||||
bool isValid = regex.IsMatch(exampleStr);
|
|
||||||
if (isValid)
|
|
||||||
{
|
|
||||||
example = exampleStr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void textBox_Enter(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
ToolTip tt = new ToolTip();
|
|
||||||
tt.Show(example, textBox, 30, -20, 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void textBox_TextChanged(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
_changeEvent?.Invoke(sender, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
private EventHandler _changeEvent;
|
|
||||||
public event EventHandler ChangeEvent
|
|
||||||
{
|
|
||||||
add
|
|
||||||
{
|
|
||||||
_changeEvent += value;
|
|
||||||
}
|
|
||||||
remove
|
|
||||||
{
|
|
||||||
_changeEvent -= value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
<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>
|
|
@ -1,6 +1,6 @@
|
|||||||
namespace CustomComponent
|
namespace Components
|
||||||
{
|
{
|
||||||
partial class PhoneTextBox
|
partial class TextBoxPhone
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обязательная переменная конструктора.
|
/// Обязательная переменная конструктора.
|
||||||
@ -28,33 +28,34 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.textBox = new System.Windows.Forms.TextBox();
|
components = new System.ComponentModel.Container();
|
||||||
this.SuspendLayout();
|
toolTipPhone = new ToolTip(components);
|
||||||
|
textBox = new TextBox();
|
||||||
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// textBox
|
// textBox
|
||||||
//
|
//
|
||||||
this.textBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
textBox.Location = new Point(16, 22);
|
||||||
this.textBox.Location = new System.Drawing.Point(3, 3);
|
textBox.Name = "textBox";
|
||||||
this.textBox.Name = "textBox";
|
textBox.Size = new Size(168, 27);
|
||||||
this.textBox.Size = new System.Drawing.Size(100, 23);
|
textBox.TabIndex = 0;
|
||||||
this.textBox.TabIndex = 0;
|
textBox.Text = "+7XXXXXXXXXX";
|
||||||
this.textBox.TextChanged += textBox_TextChanged;
|
toolTipPhone.SetToolTip(textBox, "+7XXXXXXXXXX");
|
||||||
this.textBox.Enter += textBox_Enter;
|
textBox.Click += textBox_Enter;
|
||||||
//
|
//
|
||||||
// PhoneTextBox
|
// TextBoxPhone
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
this.Controls.Add(this.textBox);
|
Controls.Add(textBox);
|
||||||
this.Name = "PhoneTextBox";
|
Name = "TextBoxPhone";
|
||||||
this.Size = new System.Drawing.Size(108, 31);
|
Size = new Size(210, 71);
|
||||||
this.ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
this.PerformLayout();
|
PerformLayout();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
private ToolTip toolTipPhone;
|
||||||
private TextBox textBox;
|
private TextBox textBox;
|
||||||
}
|
}
|
||||||
}
|
}
|
111
COP_7/TextBoxPhone.cs
Normal file
111
COP_7/TextBoxPhone.cs
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
using Components.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 Components
|
||||||
|
{
|
||||||
|
public partial class TextBoxPhone : UserControl
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public TextBoxPhone()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаблон вводимого значения
|
||||||
|
/// </summary>
|
||||||
|
private string? _phonePattern;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаблон вводимого значения
|
||||||
|
/// </summary>
|
||||||
|
public string? PhonePattern
|
||||||
|
{
|
||||||
|
get { return _phonePattern; }
|
||||||
|
set { _phonePattern = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Введенное значение
|
||||||
|
/// </summary>
|
||||||
|
public string? PhoneTextBox
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (PhonePattern == null)
|
||||||
|
{
|
||||||
|
throw new PhoneException("Шаблон не заполнен!");
|
||||||
|
}
|
||||||
|
|
||||||
|
Regex regex = new Regex(PhonePattern);
|
||||||
|
if (regex.IsMatch(textBox.Text))
|
||||||
|
{
|
||||||
|
return textBox.Text;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new PhoneException(textBox.Text + " не соответствует шаблону!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Regex regex = new Regex(PhonePattern!);
|
||||||
|
if (regex.IsMatch(value))
|
||||||
|
{
|
||||||
|
textBox.Text = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Событие, вызываемое при смене значения
|
||||||
|
/// </summary>
|
||||||
|
private EventHandler _onValueChangedEvent;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Событие, вызываемое при смене значения
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler ValueChanged
|
||||||
|
{
|
||||||
|
add
|
||||||
|
{
|
||||||
|
_onValueChangedEvent += value;
|
||||||
|
}
|
||||||
|
|
||||||
|
remove
|
||||||
|
{
|
||||||
|
_onValueChangedEvent -= value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Смена значения
|
||||||
|
/// </summary>
|
||||||
|
private void CustomPhoneBox_PhoneChanged(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("+7XXXXXXXXXX", textBox, 30, -20, visibleTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
123
COP_7/TextBoxPhone.resx
Normal file
123
COP_7/TextBoxPhone.resx
Normal 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="toolTipPhone.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
33
FormTest/Form1.Designer.cs
generated
33
FormTest/Form1.Designer.cs
generated
@ -28,22 +28,43 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
dropDownList1 = new COP_7.DropDownList();
|
dropDownList1 = new Components.DropDownList();
|
||||||
|
listBoxMany1 = new Components.ListBoxMany();
|
||||||
|
textBoxPhone2 = new Components.TextBoxPhone();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// dropDownList1
|
// dropDownList1
|
||||||
//
|
//
|
||||||
dropDownList1.Location = new Point(26, 12);
|
dropDownList1.Location = new Point(12, 22);
|
||||||
dropDownList1.Name = "dropDownList1";
|
dropDownList1.Name = "dropDownList1";
|
||||||
dropDownList1.SelectedValue = "";
|
dropDownList1.SelectedItem = " ";
|
||||||
dropDownList1.Size = new Size(157, 46);
|
dropDownList1.Size = new Size(188, 46);
|
||||||
dropDownList1.TabIndex = 0;
|
dropDownList1.TabIndex = 0;
|
||||||
//
|
//
|
||||||
|
// listBoxMany1
|
||||||
|
//
|
||||||
|
listBoxMany1.Location = new Point(225, 22);
|
||||||
|
listBoxMany1.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
listBoxMany1.Name = "listBoxMany1";
|
||||||
|
listBoxMany1.SelectedIndex = -1;
|
||||||
|
listBoxMany1.Size = new Size(222, 223);
|
||||||
|
listBoxMany1.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// textBoxPhone2
|
||||||
|
//
|
||||||
|
textBoxPhone2.Location = new Point(519, 22);
|
||||||
|
textBoxPhone2.Name = "textBoxPhone2";
|
||||||
|
textBoxPhone2.PhonePattern = null;
|
||||||
|
textBoxPhone2.Size = new Size(258, 145);
|
||||||
|
textBoxPhone2.TabIndex = 3;
|
||||||
|
//
|
||||||
// Form1
|
// Form1
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 450);
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(textBoxPhone2);
|
||||||
|
Controls.Add(listBoxMany1);
|
||||||
Controls.Add(dropDownList1);
|
Controls.Add(dropDownList1);
|
||||||
Name = "Form1";
|
Name = "Form1";
|
||||||
Text = "Form1";
|
Text = "Form1";
|
||||||
@ -52,6 +73,8 @@
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private COP_7.DropDownList dropDownList1;
|
private Components.DropDownList dropDownList1;
|
||||||
|
private Components.ListBoxMany listBoxMany1;
|
||||||
|
private Components.TextBoxPhone textBoxPhone2;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,3 +1,13 @@
|
|||||||
|
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 FormTest
|
namespace FormTest
|
||||||
{
|
{
|
||||||
public partial class Form1 : Form
|
public partial class Form1 : Form
|
||||||
|
Loading…
Reference in New Issue
Block a user