From 65deacff8e754b8573c35cc7959d5e1ff7cfeeba Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Sat, 16 Sep 2023 11:05:11 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B0=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COP/VisualComponentsLib/MyDropDownList.cs | 17 ++++++++-- COP/VisualComponentsLib/MyEmailTextBox.cs | 34 ++++++++++++------- ...igner.cs => FormForComponents.Designer.cs} | 2 +- .../{Form1.cs => FormForComponents.cs} | 10 ++++-- .../{Form1.resx => FormForComponents.resx} | 0 COP/WinForms/Program.cs | 2 +- 6 files changed, 45 insertions(+), 20 deletions(-) rename COP/WinForms/{Form1.Designer.cs => FormForComponents.Designer.cs} (99%) rename COP/WinForms/{Form1.cs => FormForComponents.cs} (89%) rename COP/WinForms/{Form1.resx => FormForComponents.resx} (100%) diff --git a/COP/VisualComponentsLib/MyDropDownList.cs b/COP/VisualComponentsLib/MyDropDownList.cs index 89ac7da..d3f3c18 100644 --- a/COP/VisualComponentsLib/MyDropDownList.cs +++ b/COP/VisualComponentsLib/MyDropDownList.cs @@ -52,10 +52,23 @@ namespace VisualComponentsLib } } } + + private EventHandler onValueChanged; + public event EventHandler ValueChanged + { + add + { + onValueChanged += value; + } + remove + { + onValueChanged -= value; + } + } + private void comboBox_SelectedValueChanged(object sender, EventArgs e) { - if (dropDownList.BackColor == Color.LightGreen) dropDownList.BackColor = Color.Tomato; - else dropDownList.BackColor = Color.LightGreen; + onValueChanged?.Invoke(sender, e); } } } diff --git a/COP/VisualComponentsLib/MyEmailTextBox.cs b/COP/VisualComponentsLib/MyEmailTextBox.cs index 1b730c3..a92d2fd 100644 --- a/COP/VisualComponentsLib/MyEmailTextBox.cs +++ b/COP/VisualComponentsLib/MyEmailTextBox.cs @@ -33,7 +33,8 @@ namespace VisualComponentsLib } else { - throw new Exception("Неправильный адрес"); + Error = "Некорректный ввод"; + return null; } } set @@ -46,10 +47,14 @@ namespace VisualComponentsLib } else { - throw new Exception("Неправильный адрес"); + Error = "Некорректный ввод"; } } } + public string Error + { + get; private set; + } public void setExample(string str) { Regex rg = new Regex(Pattern); @@ -63,23 +68,26 @@ namespace VisualComponentsLib private void textBox_Enter(object sender, EventArgs e) { int VisibleTime = 2000; //ms - ToolTip tooltip = new ToolTip(); tooltip.Show(example, emailTextBox, 30, -20, VisibleTime); } + private EventHandler onValueChanged; + public event EventHandler ValueChanged + { + add + { + onValueChanged += value; + } + remove + { + onValueChanged -= value; + } + } + 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; - } + onValueChanged?.Invoke(sender, e); } } } diff --git a/COP/WinForms/Form1.Designer.cs b/COP/WinForms/FormForComponents.Designer.cs similarity index 99% rename from COP/WinForms/Form1.Designer.cs rename to COP/WinForms/FormForComponents.Designer.cs index a5198c0..afbd80d 100644 --- a/COP/WinForms/Form1.Designer.cs +++ b/COP/WinForms/FormForComponents.Designer.cs @@ -1,6 +1,6 @@ namespace WinForms { - partial class Form1 + partial class FormForComponents { /// /// Required designer variable. diff --git a/COP/WinForms/Form1.cs b/COP/WinForms/FormForComponents.cs similarity index 89% rename from COP/WinForms/Form1.cs rename to COP/WinForms/FormForComponents.cs index d85d5f0..0937c17 100644 --- a/COP/WinForms/Form1.cs +++ b/COP/WinForms/FormForComponents.cs @@ -1,13 +1,12 @@ -using System.Security.Cryptography; using VisualComponentsLib.Object; namespace WinForms { - public partial class Form1 : Form + public partial class FormForComponents : Form { List list = new List(); List students = new List(); - public Form1() + public FormForComponents() { list = new List(); list.AddRange(new string[] { "", "", "" }); @@ -21,6 +20,11 @@ namespace WinForms dropDownList.LoadValues(new List() { "", "", "" }); emailTextBox.Pattern = @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"; listBoxObj.SetLayoutInfo(" *Name* *Group* *Faculty* *Course*", "*", "*"); + dropDownList.ValueChanged += CustomEventHandler; + } + private void CustomEventHandler(object sender, EventArgs e) + { + MessageBox.Show(" "); } private void buttonAdd_Click(object sender, EventArgs e) { diff --git a/COP/WinForms/Form1.resx b/COP/WinForms/FormForComponents.resx similarity index 100% rename from COP/WinForms/Form1.resx rename to COP/WinForms/FormForComponents.resx diff --git a/COP/WinForms/Program.cs b/COP/WinForms/Program.cs index 59ed7ae..1598162 100644 --- a/COP/WinForms/Program.cs +++ b/COP/WinForms/Program.cs @@ -11,7 +11,7 @@ namespace WinForms // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new FormForComponents()); } } } \ No newline at end of file