похоже 2 компонент готов
This commit is contained in:
parent
96c441c7aa
commit
2a817ffd5d
59
COP/VisualComponentsLib/MyEmailTextBox.Designer.cs
generated
Normal file
59
COP/VisualComponentsLib/MyEmailTextBox.Designer.cs
generated
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
namespace VisualComponentsLib
|
||||||
|
{
|
||||||
|
partial class MyEmailTextBox
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
this.emailTextBox = new System.Windows.Forms.TextBox();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// emailTextBox
|
||||||
|
//
|
||||||
|
this.emailTextBox.Location = new System.Drawing.Point(3, 3);
|
||||||
|
this.emailTextBox.Name = "emailTextBox";
|
||||||
|
this.emailTextBox.Size = new System.Drawing.Size(170, 22);
|
||||||
|
this.emailTextBox.TabIndex = 0;
|
||||||
|
this.emailTextBox.TextChanged += new System.EventHandler(this.textBox_TextChanged);
|
||||||
|
this.emailTextBox.Enter += new System.EventHandler(this.textBox_Enter);
|
||||||
|
//
|
||||||
|
// MyEmailTextBox
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.Controls.Add(this.emailTextBox);
|
||||||
|
this.Name = "MyEmailTextBox";
|
||||||
|
this.Size = new System.Drawing.Size(177, 30);
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.TextBox emailTextBox;
|
||||||
|
}
|
||||||
|
}
|
85
COP/VisualComponentsLib/MyEmailTextBox.cs
Normal file
85
COP/VisualComponentsLib/MyEmailTextBox.cs
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
using System;
|
||||||
|
using ToolTip = System.Windows.Forms.ToolTip;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace VisualComponentsLib
|
||||||
|
{
|
||||||
|
public partial class MyEmailTextBox : UserControl
|
||||||
|
{
|
||||||
|
//Шаблон для textbox
|
||||||
|
private string pattern;
|
||||||
|
//Пример ввода
|
||||||
|
private string example = "ti@gmail.com";
|
||||||
|
public MyEmailTextBox()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
public string Pattern
|
||||||
|
{
|
||||||
|
get { return pattern; }
|
||||||
|
set { pattern = value; }
|
||||||
|
}
|
||||||
|
public string TextBoxValue
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
Regex rg = new Regex(Pattern);
|
||||||
|
bool address = rg.IsMatch(emailTextBox.Text);
|
||||||
|
if (address)
|
||||||
|
{
|
||||||
|
return emailTextBox.Text;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("Неправильный адрес");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Regex rg = new Regex(Pattern);
|
||||||
|
bool address = rg.IsMatch(value);
|
||||||
|
if (address)
|
||||||
|
{
|
||||||
|
emailTextBox.Text = value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("Неправильный адрес");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void setExample(string str)
|
||||||
|
{
|
||||||
|
Regex rg = new Regex(Pattern);
|
||||||
|
bool address = rg.IsMatch(str);
|
||||||
|
if (address)
|
||||||
|
{
|
||||||
|
example = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
private void textBox_Enter(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
int VisibleTime = 2000; //ms
|
||||||
|
|
||||||
|
ToolTip tooltip = new ToolTip();
|
||||||
|
tooltip.Show(example, emailTextBox, 30, -20, VisibleTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void textBox_TextChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Regex rg = new Regex(Pattern);
|
||||||
|
bool address = rg.IsMatch(emailTextBox.Text);
|
||||||
|
if (address)
|
||||||
|
{
|
||||||
|
emailTextBox.BackColor = Color.Green;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emailTextBox.BackColor = Color.Red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
COP/VisualComponentsLib/MyEmailTextBox.resx
Normal file
120
COP/VisualComponentsLib/MyEmailTextBox.resx
Normal 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>
|
@ -48,6 +48,12 @@
|
|||||||
<Compile Include="MyDropDownList.Designer.cs">
|
<Compile Include="MyDropDownList.Designer.cs">
|
||||||
<DependentUpon>MyDropDownList.cs</DependentUpon>
|
<DependentUpon>MyDropDownList.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="MyEmailTextBox.cs">
|
||||||
|
<SubType>UserControl</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="MyEmailTextBox.Designer.cs">
|
||||||
|
<DependentUpon>MyEmailTextBox.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />
|
<Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@ -55,6 +61,9 @@
|
|||||||
<EmbeddedResource Include="MyDropDownList.resx">
|
<EmbeddedResource Include="MyDropDownList.resx">
|
||||||
<DependentUpon>MyDropDownList.cs</DependentUpon>
|
<DependentUpon>MyDropDownList.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="MyEmailTextBox.resx">
|
||||||
|
<DependentUpon>MyEmailTextBox.cs</DependentUpon>
|
||||||
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
72
COP/WinForms/Form1.Designer.cs
generated
72
COP/WinForms/Form1.Designer.cs
generated
@ -33,6 +33,12 @@
|
|||||||
buttonInfo = new Button();
|
buttonInfo = new Button();
|
||||||
labelInfo = new Label();
|
labelInfo = new Label();
|
||||||
buttonClear = new Button();
|
buttonClear = new Button();
|
||||||
|
emailTextBox = new VisualComponentsLib.MyEmailTextBox();
|
||||||
|
labelShow = new Label();
|
||||||
|
buttonShow = new Button();
|
||||||
|
buttonSetExample = new Button();
|
||||||
|
labelExample = new Label();
|
||||||
|
textBoxExample = new TextBox();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// dropDownList
|
// dropDownList
|
||||||
@ -83,6 +89,60 @@
|
|||||||
buttonClear.UseVisualStyleBackColor = true;
|
buttonClear.UseVisualStyleBackColor = true;
|
||||||
buttonClear.Click += buttonClear_Click;
|
buttonClear.Click += buttonClear_Click;
|
||||||
//
|
//
|
||||||
|
// emailTextBox
|
||||||
|
//
|
||||||
|
emailTextBox.Location = new Point(12, 132);
|
||||||
|
emailTextBox.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
emailTextBox.Name = "emailTextBox";
|
||||||
|
emailTextBox.Pattern = null;
|
||||||
|
emailTextBox.Size = new Size(179, 34);
|
||||||
|
emailTextBox.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// labelShow
|
||||||
|
//
|
||||||
|
labelShow.AutoSize = true;
|
||||||
|
labelShow.Location = new Point(12, 170);
|
||||||
|
labelShow.Name = "labelShow";
|
||||||
|
labelShow.Size = new Size(76, 20);
|
||||||
|
labelShow.TabIndex = 10;
|
||||||
|
labelShow.Text = "проверка";
|
||||||
|
//
|
||||||
|
// buttonShow
|
||||||
|
//
|
||||||
|
buttonShow.Location = new Point(12, 196);
|
||||||
|
buttonShow.Name = "buttonShow";
|
||||||
|
buttonShow.Size = new Size(94, 29);
|
||||||
|
buttonShow.TabIndex = 9;
|
||||||
|
buttonShow.Text = "Проверка";
|
||||||
|
buttonShow.UseVisualStyleBackColor = true;
|
||||||
|
buttonShow.Click += buttonShow_Click;
|
||||||
|
//
|
||||||
|
// buttonSetExample
|
||||||
|
//
|
||||||
|
buttonSetExample.Location = new Point(12, 328);
|
||||||
|
buttonSetExample.Name = "buttonSetExample";
|
||||||
|
buttonSetExample.Size = new Size(188, 29);
|
||||||
|
buttonSetExample.TabIndex = 8;
|
||||||
|
buttonSetExample.Text = "Поменять пример";
|
||||||
|
buttonSetExample.UseVisualStyleBackColor = true;
|
||||||
|
buttonSetExample.Click += buttonSetExample_Click;
|
||||||
|
//
|
||||||
|
// labelExample
|
||||||
|
//
|
||||||
|
labelExample.AutoSize = true;
|
||||||
|
labelExample.Location = new Point(12, 263);
|
||||||
|
labelExample.Name = "labelExample";
|
||||||
|
labelExample.Size = new Size(147, 20);
|
||||||
|
labelExample.TabIndex = 7;
|
||||||
|
labelExample.Text = "Для ввода примера";
|
||||||
|
//
|
||||||
|
// textBoxExample
|
||||||
|
//
|
||||||
|
textBoxExample.Location = new Point(12, 295);
|
||||||
|
textBoxExample.Name = "textBoxExample";
|
||||||
|
textBoxExample.Size = new Size(188, 27);
|
||||||
|
textBoxExample.TabIndex = 6;
|
||||||
|
//
|
||||||
// Form1
|
// Form1
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
@ -93,6 +153,12 @@
|
|||||||
Controls.Add(buttonInfo);
|
Controls.Add(buttonInfo);
|
||||||
Controls.Add(labelInfo);
|
Controls.Add(labelInfo);
|
||||||
Controls.Add(buttonClear);
|
Controls.Add(buttonClear);
|
||||||
|
Controls.Add(emailTextBox);
|
||||||
|
Controls.Add(textBoxExample);
|
||||||
|
Controls.Add(labelExample);
|
||||||
|
Controls.Add(buttonSetExample);
|
||||||
|
Controls.Add(labelShow);
|
||||||
|
Controls.Add(buttonShow);
|
||||||
Name = "Form1";
|
Name = "Form1";
|
||||||
Text = "Form1";
|
Text = "Form1";
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
@ -105,5 +171,11 @@
|
|||||||
private Button buttonInfo;
|
private Button buttonInfo;
|
||||||
private Label labelInfo;
|
private Label labelInfo;
|
||||||
private Button buttonClear;
|
private Button buttonClear;
|
||||||
|
private VisualComponentsLib.MyEmailTextBox emailTextBox;
|
||||||
|
private TextBox textBoxExample;
|
||||||
|
private Label labelExample;
|
||||||
|
private Button buttonSetExample;
|
||||||
|
private Label labelShow;
|
||||||
|
private Button buttonShow;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,6 +9,7 @@ namespace WinForms
|
|||||||
list.AddRange(new string[] { "õëåá", "ìîëîêî", "êîëáàñà" });
|
list.AddRange(new string[] { "õëåá", "ìîëîêî", "êîëáàñà" });
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
dropDownList.LoadValues(new List<string>() { "ñîê", "ÿáëîêî", "ëóê" });
|
dropDownList.LoadValues(new List<string>() { "ñîê", "ÿáëîêî", "ëóê" });
|
||||||
|
emailTextBox.Pattern = @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$";
|
||||||
}
|
}
|
||||||
private void buttonAdd_Click(object sender, EventArgs e)
|
private void buttonAdd_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@ -24,5 +25,29 @@ namespace WinForms
|
|||||||
{
|
{
|
||||||
dropDownList.Clear();
|
dropDownList.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttonSetExample_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (textBoxExample.Text == String.Empty)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
emailTextBox.setExample(textBoxExample.Text);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonShow_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (emailTextBox.TextBoxValue != null)
|
||||||
|
{
|
||||||
|
labelShow.Text = "ïîäõîäèò";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user