From 7bdd5ea8fbbeba7c3e0737decdb9c2079c8a51a6 Mon Sep 17 00:00:00 2001 From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com> Date: Mon, 14 Oct 2024 13:05:17 +0400 Subject: [PATCH] =?UTF-8?q?lab1=20-=20=D0=BF=D0=BE=D1=87=D1=82=D0=B8=20?= =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WinFormsApp1/Form1.Designer.cs | 69 ++++++++++ WinFormsLibrary1/WinFormsApp1/Form1.cs | 24 ++++ WinFormsLibrary1/WinFormsApp1/Form1.resx | 120 ++++++++++++++++++ WinFormsLibrary1/WinFormsApp1/Program.cs | 17 +++ .../WinFormsApp1/WinFormsApp1.csproj | 15 +++ WinFormsLibrary1/WinFormsLibrary1.sln | 31 +++++ .../WinFormsLibrary1/ComboBox.Designer.cs | 42 ++++++ WinFormsLibrary1/WinFormsLibrary1/ComboBox.cs | 38 ++++++ .../WinFormsLibrary1/ComboBox.resx | 120 ++++++++++++++++++ .../DateInputControl.Designer.cs | 58 +++++++++ .../WinFormsLibrary1/DateInputControl.cs | 68 ++++++++++ .../WinFormsLibrary1/DateInputControl.resx | 120 ++++++++++++++++++ .../WinFormsLibrary1/ListBox.Designer.cs | 42 ++++++ WinFormsLibrary1/WinFormsLibrary1/ListBox.cs | 98 ++++++++++++++ .../WinFormsLibrary1/ListBox.resx | 120 ++++++++++++++++++ .../WinFormsLibrary1/WinFormsLibrary1.csproj | 10 ++ WinFormsLibrary1/WinFormsLibrary2/Class1.cs | 6 + .../WinFormsLibrary2/Form1.Designer.cs | 39 ++++++ WinFormsLibrary1/WinFormsLibrary2/Form1.cs | 20 +++ WinFormsLibrary1/WinFormsLibrary2/Form1.resx | 120 ++++++++++++++++++ .../WinFormsLibrary2/UserControl1.Designer.cs | 37 ++++++ .../WinFormsLibrary2/UserControl1.cs | 20 +++ .../WinFormsLibrary2/UserControl1.resx | 120 ++++++++++++++++++ .../WinFormsLibrary2/WinFormsLibrary2.csproj | 10 ++ 24 files changed, 1364 insertions(+) create mode 100644 WinFormsLibrary1/WinFormsApp1/Form1.Designer.cs create mode 100644 WinFormsLibrary1/WinFormsApp1/Form1.cs create mode 100644 WinFormsLibrary1/WinFormsApp1/Form1.resx create mode 100644 WinFormsLibrary1/WinFormsApp1/Program.cs create mode 100644 WinFormsLibrary1/WinFormsApp1/WinFormsApp1.csproj create mode 100644 WinFormsLibrary1/WinFormsLibrary1.sln create mode 100644 WinFormsLibrary1/WinFormsLibrary1/ComboBox.Designer.cs create mode 100644 WinFormsLibrary1/WinFormsLibrary1/ComboBox.cs create mode 100644 WinFormsLibrary1/WinFormsLibrary1/ComboBox.resx create mode 100644 WinFormsLibrary1/WinFormsLibrary1/DateInputControl.Designer.cs create mode 100644 WinFormsLibrary1/WinFormsLibrary1/DateInputControl.cs create mode 100644 WinFormsLibrary1/WinFormsLibrary1/DateInputControl.resx create mode 100644 WinFormsLibrary1/WinFormsLibrary1/ListBox.Designer.cs create mode 100644 WinFormsLibrary1/WinFormsLibrary1/ListBox.cs create mode 100644 WinFormsLibrary1/WinFormsLibrary1/ListBox.resx create mode 100644 WinFormsLibrary1/WinFormsLibrary1/WinFormsLibrary1.csproj create mode 100644 WinFormsLibrary1/WinFormsLibrary2/Class1.cs create mode 100644 WinFormsLibrary1/WinFormsLibrary2/Form1.Designer.cs create mode 100644 WinFormsLibrary1/WinFormsLibrary2/Form1.cs create mode 100644 WinFormsLibrary1/WinFormsLibrary2/Form1.resx create mode 100644 WinFormsLibrary1/WinFormsLibrary2/UserControl1.Designer.cs create mode 100644 WinFormsLibrary1/WinFormsLibrary2/UserControl1.cs create mode 100644 WinFormsLibrary1/WinFormsLibrary2/UserControl1.resx create mode 100644 WinFormsLibrary1/WinFormsLibrary2/WinFormsLibrary2.csproj diff --git a/WinFormsLibrary1/WinFormsApp1/Form1.Designer.cs b/WinFormsLibrary1/WinFormsApp1/Form1.Designer.cs new file mode 100644 index 0000000..e168305 --- /dev/null +++ b/WinFormsLibrary1/WinFormsApp1/Form1.Designer.cs @@ -0,0 +1,69 @@ +using System.Windows.Forms; +using WinFormsLibrary1; + +namespace WinFormsApp1 +{ + partial class Form1 + { + private System.ComponentModel.IContainer components = null; + + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + private void InitializeComponent() + { + comboBoxUserControl = new ComboBox(); + listBoxUserControl = new ListBox(); + dateInputControl1 = new DateInputControl(); + SuspendLayout(); + // + // comboBoxUserControl + // + comboBoxUserControl.Location = new Point(13, 15); + comboBoxUserControl.Margin = new Padding(4, 5, 4, 5); + comboBoxUserControl.Name = "comboBoxUserControl"; + comboBoxUserControl.Size = new Size(160, 28); + comboBoxUserControl.TabIndex = 0; + // + // listBoxUserControl + // + listBoxUserControl.Location = new Point(13, 231); + listBoxUserControl.Margin = new Padding(4, 5, 4, 5); + listBoxUserControl.Name = "listBoxUserControl"; + listBoxUserControl.Size = new Size(159, 144); + listBoxUserControl.TabIndex = 2; + // + // dateInputControl1 + // + dateInputControl1.Date = ""; + dateInputControl1.Location = new Point(13, 107); + dateInputControl1.Margin = new Padding(4, 5, 4, 5); + dateInputControl1.Name = "dateInputControl1"; + dateInputControl1.Size = new Size(166, 96); + dateInputControl1.TabIndex = 3; + // + // Form1 + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(400, 462); + Controls.Add(dateInputControl1); + Controls.Add(listBoxUserControl); + Controls.Add(comboBoxUserControl); + Margin = new Padding(4, 5, 4, 5); + Name = "Form1"; + Text = "Form1"; + ResumeLayout(false); + } + + private ComboBox comboBoxUserControl; + private ListBox listBoxUserControl; + private DateInputControl dateInputControl1; + } +} \ No newline at end of file diff --git a/WinFormsLibrary1/WinFormsApp1/Form1.cs b/WinFormsLibrary1/WinFormsApp1/Form1.cs new file mode 100644 index 0000000..c6a3bb0 --- /dev/null +++ b/WinFormsLibrary1/WinFormsApp1/Form1.cs @@ -0,0 +1,24 @@ +using System; +using System.Windows.Forms; +using WinFormsLibrary1; + +namespace WinFormsApp1 +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + private void ComboBoxUserControl_SelectedValueChanged(object sender, EventArgs e) + { + MessageBox.Show($"ComboBox selected: {comboBoxUserControl.SelectedValue}"); + } + + private void ListBoxUserControl_SelectedValueChanged(object sender, EventArgs e) + { + MessageBox.Show($"ListBox selected: {listBoxUserControl.SelectedValue}"); + } + } +} \ No newline at end of file diff --git a/WinFormsLibrary1/WinFormsApp1/Form1.resx b/WinFormsLibrary1/WinFormsApp1/Form1.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/WinFormsLibrary1/WinFormsApp1/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/WinFormsLibrary1/WinFormsApp1/Program.cs b/WinFormsLibrary1/WinFormsApp1/Program.cs new file mode 100644 index 0000000..1e39c2a --- /dev/null +++ b/WinFormsLibrary1/WinFormsApp1/Program.cs @@ -0,0 +1,17 @@ +namespace WinFormsApp1 +{ + 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 diff --git a/WinFormsLibrary1/WinFormsApp1/WinFormsApp1.csproj b/WinFormsLibrary1/WinFormsApp1/WinFormsApp1.csproj new file mode 100644 index 0000000..3e8ed13 --- /dev/null +++ b/WinFormsLibrary1/WinFormsApp1/WinFormsApp1.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net8.0-windows + enable + true + enable + + + + + + + \ No newline at end of file diff --git a/WinFormsLibrary1/WinFormsLibrary1.sln b/WinFormsLibrary1/WinFormsLibrary1.sln new file mode 100644 index 0000000..54ee565 --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary1.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34916.146 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsLibrary1", "WinFormsLibrary1\WinFormsLibrary1.csproj", "{4F13F436-1BE0-4F8D-A720-FCBF3893BA55}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsApp1", "WinFormsApp1\WinFormsApp1.csproj", "{4B1A0E96-B60A-4D73-B4AB-CF5157E593E5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4F13F436-1BE0-4F8D-A720-FCBF3893BA55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F13F436-1BE0-4F8D-A720-FCBF3893BA55}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F13F436-1BE0-4F8D-A720-FCBF3893BA55}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F13F436-1BE0-4F8D-A720-FCBF3893BA55}.Release|Any CPU.Build.0 = Release|Any CPU + {4B1A0E96-B60A-4D73-B4AB-CF5157E593E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4B1A0E96-B60A-4D73-B4AB-CF5157E593E5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4B1A0E96-B60A-4D73-B4AB-CF5157E593E5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4B1A0E96-B60A-4D73-B4AB-CF5157E593E5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {30BE3CA4-B770-4A5A-A07E-FE2B703C6B13} + EndGlobalSection +EndGlobal diff --git a/WinFormsLibrary1/WinFormsLibrary1/ComboBox.Designer.cs b/WinFormsLibrary1/WinFormsLibrary1/ComboBox.Designer.cs new file mode 100644 index 0000000..65b19af --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary1/ComboBox.Designer.cs @@ -0,0 +1,42 @@ +namespace WinFormsLibrary1 +{ + partial class ComboBoxUserControl + { + private System.ComponentModel.IContainer components = null; + + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + private void InitializeComponent() + { + this.comboBox = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // comboBox + // + this.comboBox.FormattingEnabled = true; + this.comboBox.Location = new System.Drawing.Point(0, 0); + this.comboBox.Name = "comboBox"; + this.comboBox.Size = new System.Drawing.Size(121, 21); + this.comboBox.TabIndex = 0; + this.comboBox.SelectedIndexChanged += new System.EventHandler(this.comboBox_SelectedIndexChanged); + // + // ComboBoxUserControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.comboBox); + this.Name = "ComboBoxUserControl"; + this.Size = new System.Drawing.Size(121, 21); + this.ResumeLayout(false); + } + + private System.Windows.Forms.ComboBox comboBox; + } +} \ No newline at end of file diff --git a/WinFormsLibrary1/WinFormsLibrary1/ComboBox.cs b/WinFormsLibrary1/WinFormsLibrary1/ComboBox.cs new file mode 100644 index 0000000..efd6727 --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary1/ComboBox.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; + +namespace WinFormsLibrary1 +{ + public partial class ComboBoxUserControl : UserControl + { + public ComboBoxUserControl() + { + InitializeComponent(); + } + + public event EventHandler SelectedValueChanged; + + public void AddItem(string item) + { + comboBox.Items.Add(item); + } + + public void ClearItems() + { + comboBox.Items.Clear(); + } + + public string SelectedValue + { + get => comboBox.SelectedItem?.ToString() ?? string.Empty; + set => comboBox.SelectedItem = value; + } + + private void comboBox_SelectedIndexChanged(object sender, EventArgs e) + { + SelectedValueChanged?.Invoke(this, e); + } + } +} \ No newline at end of file diff --git a/WinFormsLibrary1/WinFormsLibrary1/ComboBox.resx b/WinFormsLibrary1/WinFormsLibrary1/ComboBox.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary1/ComboBox.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/WinFormsLibrary1/WinFormsLibrary1/DateInputControl.Designer.cs b/WinFormsLibrary1/WinFormsLibrary1/DateInputControl.Designer.cs new file mode 100644 index 0000000..4f0c928 --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary1/DateInputControl.Designer.cs @@ -0,0 +1,58 @@ +namespace WinFormsLibrary1 +{ + partial class DateInputControl + { + private System.ComponentModel.IContainer components = null; + + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + private void InitializeComponent() + { + textBoxDate = new TextBox(); + errorLabel = new Label(); + SuspendLayout(); + // + // textBoxDate + // + textBoxDate.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxDate.Location = new Point(0, 0); + textBoxDate.Margin = new Padding(4, 5, 4, 5); + textBoxDate.Name = "textBoxDate"; + textBoxDate.Size = new Size(146, 27); + textBoxDate.TabIndex = 0; + // + // errorLabel + // + errorLabel.AutoSize = true; + errorLabel.ForeColor = Color.Red; + errorLabel.Location = new Point(0, 38); + errorLabel.Margin = new Padding(4, 0, 4, 0); + errorLabel.Name = "errorLabel"; + errorLabel.Size = new Size(0, 20); + errorLabel.TabIndex = 1; + errorLabel.Visible = false; + // + // DateInputControl + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(errorLabel); + Controls.Add(textBoxDate); + Margin = new Padding(4, 5, 4, 5); + Name = "DateInputControl"; + Size = new Size(149, 88); + ResumeLayout(false); + PerformLayout(); + } + + private System.Windows.Forms.TextBox textBoxDate; + private System.Windows.Forms.Label errorLabel; + } +} \ No newline at end of file diff --git a/WinFormsLibrary1/WinFormsLibrary1/DateInputControl.cs b/WinFormsLibrary1/WinFormsLibrary1/DateInputControl.cs new file mode 100644 index 0000000..37e8ab9 --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary1/DateInputControl.cs @@ -0,0 +1,68 @@ +using System.Globalization; + +namespace WinFormsLibrary1 +{ + public partial class DateInputControl : UserControl + { + private string DateFormat{ get; set; } + + public DateInputControl() + { + InitializeComponent(); + } + + public DateTime Date + { + get + { + if(string.IsNullOrEmpty(textBoxDate.Text)) + { + throw new Exception("Введите дату"); + } + else if(string.IsNullOrEmpty(DateFormat)) + { + throw new Exception("Шаблон не задан"); + } + else if (Validate()) + { + DateTime parsedDate; + if (DateTime.TryParseExact(textBoxDate.Text, DateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out parsedDate)) + { + return parsedDate; + } + } + throw new Exception("Неправильно введена дата"); + } + set + { + if (string.IsNullOrEmpty(DateFormat)) + { + textBoxDate.Text = value.ToString(DateFormat); + } + textBoxDate.Text = string.Empty; + } + } + + private void TextBoxDate_TextChanged(object sender, EventArgs e) + { + ValidateDate(); + } + + private bool ValidateDate() + { + DateTime parsedDate; + + if (DateTime.TryParseExact(textBoxDate.Text, DateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out parsedDate)) + { + errorLabel.Visible = false; + return true; + } + else + { + errorLabel.Visible = true; + errorLabel.Text = $"Неверный формат даты. Используйте формат {DateFormat}."; + return false; + } + } + } +} \ No newline at end of file diff --git a/WinFormsLibrary1/WinFormsLibrary1/DateInputControl.resx b/WinFormsLibrary1/WinFormsLibrary1/DateInputControl.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary1/DateInputControl.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/WinFormsLibrary1/WinFormsLibrary1/ListBox.Designer.cs b/WinFormsLibrary1/WinFormsLibrary1/ListBox.Designer.cs new file mode 100644 index 0000000..2d5e613 --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary1/ListBox.Designer.cs @@ -0,0 +1,42 @@ +namespace WinFormsLibrary1 +{ + partial class ListBoxUserControl + { + private System.ComponentModel.IContainer components = null; + + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + private void InitializeComponent() + { + this.listBox = new System.Windows.Forms.ListBox(); + this.SuspendLayout(); + // + // listBox + // + this.listBox.FormattingEnabled = true; + this.listBox.Location = new System.Drawing.Point(0, 0); + this.listBox.Name = "listBox"; + this.listBox.Size = new System.Drawing.Size(120, 95); + this.listBox.TabIndex = 0; + this.listBox.SelectedIndexChanged += new System.EventHandler(this.listBox_SelectedIndexChanged); + // + // ListBoxUserControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.listBox); + this.Name = "ListBoxUserControl"; + this.Size = new System.Drawing.Size(120, 95); + this.ResumeLayout(false); + } + + private System.Windows.Forms.ListBox listBox; + } +} \ No newline at end of file diff --git a/WinFormsLibrary1/WinFormsLibrary1/ListBox.cs b/WinFormsLibrary1/WinFormsLibrary1/ListBox.cs new file mode 100644 index 0000000..fb0d8d8 --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary1/ListBox.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.RegularExpressions; +using System.Windows.Forms; + +namespace WinFormsLibrary1 +{ + public partial class ListBoxUserControl : UserControl + { + private string? _template; + + private string _startSymbol; + + private string _endSymbol; + public int SelectedIndex + { + get + { + return listBox.SelectedIndex; + } + set + { + listBox.SelectedIndex = value; + } + } + public ListBoxUserControl() + { + InitializeComponent(); + } + public void SetParams(string template, string fromChar, string toChar) + { + _template = template; + _startSymbol = fromChar; + _endSymbol = toChar; + } + + public T? GetObject() where T : class, new() + { + if (listBox.SelectedIndex == -1) + { + return null; + } + + string selectedString = listBox.SelectedItem.ToString()!; + T obj = new T(); + + string pattern = $@"{Regex.Escape(_startSymbol)}(.*?){Regex.Escape(_endSymbol)}"; + MatchCollection matches = Regex.Matches(_template, pattern); + + string[] words = selectedString.Split(' '); + + int wordIndex = 0; + + foreach (Match match in matches) + { + string propertyName = match.Groups[1].Value; + var property = obj.GetType().GetProperty(propertyName); + if (property != null && property.CanWrite) + { + if (wordIndex < words.Length) + { + string propertyValue = words[wordIndex]; + property.SetValue(obj, Convert.ChangeType(propertyValue, property.PropertyType)); + wordIndex++; + } + } + } + + return obj; + } + + public void AddObject(T obj) + { + if (obj == null) + { + throw new ArgumentNullException("Добавляемый объект не существует!"); + } + if (string.IsNullOrEmpty(_template) || string.IsNullOrEmpty(_startSymbol) || string.IsNullOrEmpty(_endSymbol)) + { + throw new Exception("Заполните макетную строку!"); + } + if (!_template.Contains(_startSymbol) || !_template.Contains(_endSymbol)) + { + throw new Exception("Макетная строка не содержит нужные элементы!"); + } + + string processedString = _template; + foreach (var property in obj.GetType().GetProperties()) + { + string placeholder = $"{_startSymbol}{property.Name}{_endSymbol}"; + processedString = processedString.Replace(placeholder, $"{_startSymbol}{property.GetValue(obj)}{_endSymbol}"); + } + + listBox.Items.Add(processedString); + } + } +} \ No newline at end of file diff --git a/WinFormsLibrary1/WinFormsLibrary1/ListBox.resx b/WinFormsLibrary1/WinFormsLibrary1/ListBox.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary1/ListBox.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/WinFormsLibrary1/WinFormsLibrary1/WinFormsLibrary1.csproj b/WinFormsLibrary1/WinFormsLibrary1/WinFormsLibrary1.csproj new file mode 100644 index 0000000..3e210aa --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary1/WinFormsLibrary1.csproj @@ -0,0 +1,10 @@ + + + + net8.0-windows + enable + true + enable + + + diff --git a/WinFormsLibrary1/WinFormsLibrary2/Class1.cs b/WinFormsLibrary1/WinFormsLibrary2/Class1.cs new file mode 100644 index 0000000..a4f3a21 --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary2/Class1.cs @@ -0,0 +1,6 @@ +namespace WinFormsLibrary2 +{ + public class Class1 + { + } +} diff --git a/WinFormsLibrary1/WinFormsLibrary2/Form1.Designer.cs b/WinFormsLibrary1/WinFormsLibrary2/Form1.Designer.cs new file mode 100644 index 0000000..2a900af --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary2/Form1.Designer.cs @@ -0,0 +1,39 @@ +namespace WinFormsLibrary2 +{ + 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() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "Form1"; + } + + #endregion + } +} \ No newline at end of file diff --git a/WinFormsLibrary1/WinFormsLibrary2/Form1.cs b/WinFormsLibrary1/WinFormsLibrary2/Form1.cs new file mode 100644 index 0000000..b7f544e --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary2/Form1.cs @@ -0,0 +1,20 @@ +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 WinFormsLibrary2 +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + } +} diff --git a/WinFormsLibrary1/WinFormsLibrary2/Form1.resx b/WinFormsLibrary1/WinFormsLibrary2/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary2/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/WinFormsLibrary1/WinFormsLibrary2/UserControl1.Designer.cs b/WinFormsLibrary1/WinFormsLibrary2/UserControl1.Designer.cs new file mode 100644 index 0000000..de494f2 --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary2/UserControl1.Designer.cs @@ -0,0 +1,37 @@ +namespace WinFormsLibrary2 +{ + partial class UserControl1 + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + } + + #endregion + } +} diff --git a/WinFormsLibrary1/WinFormsLibrary2/UserControl1.cs b/WinFormsLibrary1/WinFormsLibrary2/UserControl1.cs new file mode 100644 index 0000000..09476f6 --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary2/UserControl1.cs @@ -0,0 +1,20 @@ +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 WinFormsLibrary2 +{ + public partial class UserControl1 : UserControl + { + public UserControl1() + { + InitializeComponent(); + } + } +} diff --git a/WinFormsLibrary1/WinFormsLibrary2/UserControl1.resx b/WinFormsLibrary1/WinFormsLibrary2/UserControl1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary2/UserControl1.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/WinFormsLibrary1/WinFormsLibrary2/WinFormsLibrary2.csproj b/WinFormsLibrary1/WinFormsLibrary2/WinFormsLibrary2.csproj new file mode 100644 index 0000000..060aa1c --- /dev/null +++ b/WinFormsLibrary1/WinFormsLibrary2/WinFormsLibrary2.csproj @@ -0,0 +1,10 @@ + + + + net6.0-windows + enable + true + enable + + +