diff --git a/COP_7/COP_7.sln b/COP_7/COP_7.sln index 6011cfa..155c14f 100644 --- a/COP_7/COP_7.sln +++ b/COP_7/COP_7.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34723.18 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "COP_7", "COP_7.csproj", "{0E0FD0F8-FAD2-4C5F-9F4E-E53516BCB322}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Components", "Components.csproj", "{0E0FD0F8-FAD2-4C5F-9F4E-E53516BCB322}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FormTest", "..\FormTest\FormTest.csproj", "{EB2A68E5-EF5C-48B2-90DF-E5CA53F65202}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {0E0FD0F8-FAD2-4C5F-9F4E-E53516BCB322}.Debug|Any CPU.Build.0 = Debug|Any CPU {0E0FD0F8-FAD2-4C5F-9F4E-E53516BCB322}.Release|Any CPU.ActiveCfg = Release|Any CPU {0E0FD0F8-FAD2-4C5F-9F4E-E53516BCB322}.Release|Any CPU.Build.0 = Release|Any CPU + {EB2A68E5-EF5C-48B2-90DF-E5CA53F65202}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EB2A68E5-EF5C-48B2-90DF-E5CA53F65202}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EB2A68E5-EF5C-48B2-90DF-E5CA53F65202}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EB2A68E5-EF5C-48B2-90DF-E5CA53F65202}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/COP_7/COP_7.csproj b/COP_7/Components.csproj similarity index 100% rename from COP_7/COP_7.csproj rename to COP_7/Components.csproj diff --git a/COP_7/DropDownList.Designer.cs b/COP_7/DropDownList.Designer.cs new file mode 100644 index 0000000..5247332 --- /dev/null +++ b/COP_7/DropDownList.Designer.cs @@ -0,0 +1,56 @@ +namespace COP_7 +{ + partial class DropDownList + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + ComboBox = new ComboBox(); + SuspendLayout(); + // + // ComboBox + // + ComboBox.FormattingEnabled = true; + ComboBox.Location = new Point(-1, 6); + ComboBox.Name = "ComboBox"; + ComboBox.Size = new Size(151, 28); + ComboBox.TabIndex = 0; + // + // DropDownList + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(ComboBox); + Name = "DropDownList"; + Size = new Size(150, 37); + ResumeLayout(false); + } + + #endregion + + private ComboBox ComboBox; + } +} diff --git a/COP_7/DropDownList.cs b/COP_7/DropDownList.cs new file mode 100644 index 0000000..4a3a369 --- /dev/null +++ b/COP_7/DropDownList.cs @@ -0,0 +1,68 @@ +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 COP_7 +{ + 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() + { + InitializeComponent(); + + } + + public string SelectedValue + { + get + { + return ComboBox.Items.Contains(ComboBox.SelectedItem) ? ComboBox.SelectedItem?.ToString() ?? "" : ""; + } + set + { + if (ComboBox.Items.Contains(value)) + { + ComboBox.SelectedItem = value; + } + else + { + ComboBox.SelectedIndex = -1; + } + } + } + + public void Clear() + { + Items.Clear(); + } + + private void comboBox_SelectedIndexChanged(object sender, EventArgs e) + { + _сhangeEvent?.Invoke(this, e); + } + } +} diff --git a/COP_7/DropDownList.resx b/COP_7/DropDownList.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/COP_7/DropDownList.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/COP_7/ListBoxMany.Designer.cs b/COP_7/ListBoxMany.Designer.cs new file mode 100644 index 0000000..da76708 --- /dev/null +++ b/COP_7/ListBoxMany.Designer.cs @@ -0,0 +1,61 @@ +namespace CustomComponent +{ + partial class ListBoxMany + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + this.listBox = new System.Windows.Forms.ListBox(); + this.SuspendLayout(); + // + // listBox + // + this.listBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.listBox.FormattingEnabled = true; + this.listBox.ItemHeight = 15; + this.listBox.Location = new System.Drawing.Point(0, 0); + this.listBox.Name = "listBox"; + this.listBox.Size = new System.Drawing.Size(300, 300); + this.listBox.TabIndex = 0; + // + // ListBoxMany + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.listBox); + this.Name = "ListBoxMany"; + this.Size = new System.Drawing.Size(300, 300); + this.ResumeLayout(false); + + } + + #endregion + + private ListBox listBox; + } +} diff --git a/COP_7/ListBoxMany.cs b/COP_7/ListBoxMany.cs new file mode 100644 index 0000000..29a6fed --- /dev/null +++ b/COP_7/ListBoxMany.cs @@ -0,0 +1,108 @@ +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 CustomComponent +{ + public partial class ListBoxMany : UserControl + { + private string LayoutString; + private string StartS; + private string EndS; + private int SelectedStr; + + public ListBoxMany() + { + InitializeComponent(); + } + + public int SelectedIndex + { + get + { + if (listBox.SelectedIndex == -1) + { + return -1; + } + return listBox.SelectedIndex; + } + set + { + if (listBox.Items.Count != 0) + { + listBox.SelectedIndex = value; + } + } + } + public void SetLayout(string layoutString, string startS, string endS) + { + if (layoutString == null || startS == null || endS == null) return; + LayoutString = layoutString; + StartS = startS; + EndS = endS; + } + public void AddItemInList(T Object, int rowIndex, int columnIndex) + { + if (Object == null) + { + 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() 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; + } + int startS = SelectedStr.IndexOf(StartS); + int endS = SelectedStr.IndexOf(EndS); + if (startS == -1 || endS == -1) + { + break; + } + string propValue = SelectedStr.Substring(startS + 1, endS - startS - 1); + SelectedStr = SelectedStr.Substring(endS + 1); + prop.SetValue(currentObject, Convert.ChangeType(propValue, prop.PropertyType)); + } + return currentObject; + } + } +} diff --git a/COP_7/ListBoxMany.resx b/COP_7/ListBoxMany.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/COP_7/ListBoxMany.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/COP_7/PhoneTextBox.Designer.cs b/COP_7/PhoneTextBox.Designer.cs new file mode 100644 index 0000000..8120f23 --- /dev/null +++ b/COP_7/PhoneTextBox.Designer.cs @@ -0,0 +1,60 @@ +namespace CustomComponent +{ + partial class PhoneTextBox + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + this.textBox = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // textBox + // + this.textBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + this.textBox.Location = new System.Drawing.Point(3, 3); + this.textBox.Name = "textBox"; + this.textBox.Size = new System.Drawing.Size(100, 23); + this.textBox.TabIndex = 0; + this.textBox.TextChanged += textBox_TextChanged; + this.textBox.Enter += textBox_Enter; + // + // PhoneTextBox + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.textBox); + this.Name = "PhoneTextBox"; + this.Size = new System.Drawing.Size(108, 31); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBox; + } +} diff --git a/COP_7/PhoneTextBox.cs b/COP_7/PhoneTextBox.cs new file mode 100644 index 0000000..aa74d43 --- /dev/null +++ b/COP_7/PhoneTextBox.cs @@ -0,0 +1,100 @@ +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; + } + } + } +} diff --git a/COP_7/PhoneTextBox.resx b/COP_7/PhoneTextBox.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/COP_7/PhoneTextBox.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FormTest/Form1.Designer.cs b/FormTest/Form1.Designer.cs new file mode 100644 index 0000000..b5c42b4 --- /dev/null +++ b/FormTest/Form1.Designer.cs @@ -0,0 +1,57 @@ +namespace FormTest +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dropDownList1 = new COP_7.DropDownList(); + SuspendLayout(); + // + // dropDownList1 + // + dropDownList1.Location = new Point(26, 12); + dropDownList1.Name = "dropDownList1"; + dropDownList1.SelectedValue = ""; + dropDownList1.Size = new Size(157, 46); + dropDownList1.TabIndex = 0; + // + // Form1 + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dropDownList1); + Name = "Form1"; + Text = "Form1"; + ResumeLayout(false); + } + + #endregion + + private COP_7.DropDownList dropDownList1; + } +} diff --git a/FormTest/Form1.cs b/FormTest/Form1.cs new file mode 100644 index 0000000..296891b --- /dev/null +++ b/FormTest/Form1.cs @@ -0,0 +1,10 @@ +namespace FormTest +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + } +} diff --git a/FormTest/Form1.resx b/FormTest/Form1.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FormTest/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FormTest/FormTest.csproj b/FormTest/FormTest.csproj new file mode 100644 index 0000000..22ab6d3 --- /dev/null +++ b/FormTest/FormTest.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + \ No newline at end of file diff --git a/FormTest/Program.cs b/FormTest/Program.cs new file mode 100644 index 0000000..e83d203 --- /dev/null +++ b/FormTest/Program.cs @@ -0,0 +1,17 @@ +namespace FormTest +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file