From e73a259ccb6ebef55ea93ab1c59f5d1eb5c49013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A5=D0=B0=D1=80=D0=BB?= =?UTF-8?q?=D0=B0=D0=BC=D0=BE=D0=B2?= Date: Thu, 21 Sep 2023 23:28:05 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=201=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Component_1/Class1.cs | 6 -- Component_1/List_with_choice.Designer.cs | 86 ++++++++++++++++ Component_1/List_with_choice.cs | 125 +++++++++++++++++++++++ Component_1/List_with_choice.resx | 60 +++++++++++ Components/Components.csproj | 4 + Components/Components.sln | 6 ++ Components/Form1.Designer.cs | 26 ++++- Components/Form1.resx | 62 +---------- 8 files changed, 304 insertions(+), 71 deletions(-) delete mode 100644 Component_1/Class1.cs create mode 100644 Component_1/List_with_choice.Designer.cs create mode 100644 Component_1/List_with_choice.cs create mode 100644 Component_1/List_with_choice.resx diff --git a/Component_1/Class1.cs b/Component_1/Class1.cs deleted file mode 100644 index db06c37..0000000 --- a/Component_1/Class1.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Component_1 -{ - public class Class1 - { - } -} \ No newline at end of file diff --git a/Component_1/List_with_choice.Designer.cs b/Component_1/List_with_choice.Designer.cs new file mode 100644 index 0000000..0328fe5 --- /dev/null +++ b/Component_1/List_with_choice.Designer.cs @@ -0,0 +1,86 @@ +namespace Component_1 +{ + partial class List_with_choice + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + checkedListBox1 = new CheckedListBox(); + button_Load = new Button(); + button_Clean = new Button(); + SuspendLayout(); + // + // checkedListBox1 + // + checkedListBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + checkedListBox1.FormattingEnabled = true; + checkedListBox1.Location = new Point(85, 23); + checkedListBox1.Name = "checkedListBox1"; + checkedListBox1.Size = new Size(201, 92); + checkedListBox1.TabIndex = 0; + checkedListBox1.SelectedIndexChanged += checkedListBox1_SelectedIndexChanged; + // + // button_Load + // + button_Load.Anchor = AnchorStyles.Bottom; + button_Load.Location = new Point(6, 146); + button_Load.Name = "button_Load"; + button_Load.Size = new Size(161, 29); + button_Load.TabIndex = 1; + button_Load.Text = "Заполнить список"; + button_Load.UseVisualStyleBackColor = true; + button_Load.Click += button_Load_Click; + // + // button_Clean + // + button_Clean.Anchor = AnchorStyles.Bottom; + button_Clean.Location = new Point(203, 146); + button_Clean.Name = "button_Clean"; + button_Clean.Size = new Size(153, 29); + button_Clean.TabIndex = 2; + button_Clean.Text = "Очистить список"; + button_Clean.UseVisualStyleBackColor = true; + button_Clean.Click += button_Clean_Click; + // + // List_with_choice + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(button_Clean); + Controls.Add(button_Load); + Controls.Add(checkedListBox1); + Name = "List_with_choice"; + Size = new Size(371, 198); + ResumeLayout(false); + } + + #endregion + + private CheckedListBox checkedListBox1; + private Button button_Load; + private Button button_Clean; + } +} diff --git a/Component_1/List_with_choice.cs b/Component_1/List_with_choice.cs new file mode 100644 index 0000000..05baf52 --- /dev/null +++ b/Component_1/List_with_choice.cs @@ -0,0 +1,125 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Component_1 +{ + public partial class List_with_choice : UserControl + { + private event EventHandler? _checkedlistChanged; + private event Action? _errorOccured; + public string Error { get; private set; } + + public String Element + { + get + { + if (checkedListBox1.SelectedItem != null) return checkedListBox1.SelectedItem.ToString(); + else return string.Empty; + } + set + { + checkedListBox1.SelectedItem = value; + } + } + + public event EventHandler Checkedlist + { + add { _checkedlistChanged += value; } + remove { _checkedlistChanged -= value; } + } + public event Action AnErrorOccurred + { + add { _errorOccured += value; } + remove { _errorOccured -= value; } + } + + public List_with_choice() + { + InitializeComponent(); + Error = string.Empty; + } + + public void Fill_List(string str) //метод заполнения списка + { + if (str == null) + { + MessageBox.Show("Вы не ввели строку"); + return; + } + + string[] list = str.Split(' '); + foreach (string s in list) + { + checkedListBox1.Items.Add(s); + } + } + public void Clean_List() //метод очистки списка + { + checkedListBox1.Items.Clear(); + } + private void button_Load_Click(object sender, EventArgs e) + { + string value = ""; + if (InputBox("Заполнение списка", "Пожалуйста введите строку", ref value) == DialogResult.OK) + { + try + { + Fill_List(value); + _checkedlistChanged?.Invoke(this, e); + } + catch (Exception ex) + { + Error = ex.Message; + _errorOccured?.Invoke(); + } + } + } + + private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e) + { + + } + public static DialogResult InputBox(string title, string promptText, ref string value)//диалоговое окно + { + Form form = new Form(); + Label label = new Label(); + TextBox textBox = new TextBox(); + Button buttonOk = new Button(); + Button buttonCancel = new Button(); + form.Text = title; + label.Text = promptText; + buttonOk.Text = "OK"; + buttonCancel.Text = "Cancel"; + buttonOk.DialogResult = DialogResult.OK; + buttonCancel.DialogResult = DialogResult.Cancel; + label.SetBounds(36, 36, 372, 13); + textBox.SetBounds(36, 86, 700, 20); + buttonOk.SetBounds(228, 160, 160, 60); + buttonCancel.SetBounds(400, 160, 160, 60); + label.AutoSize = true; + form.ClientSize = new Size(796, 307); + form.FormBorderStyle = FormBorderStyle.FixedDialog; + form.StartPosition = FormStartPosition.CenterScreen; + form.MinimizeBox = false; + form.MaximizeBox = false; + form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel }); + form.AcceptButton = buttonOk; + form.CancelButton = buttonCancel; + DialogResult dialogResult = form.ShowDialog(); + value = textBox.Text; + return dialogResult; + } + private void button_Clean_Click(object sender, EventArgs e) + { + Clean_List(); + } + } +} diff --git a/Component_1/List_with_choice.resx b/Component_1/List_with_choice.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Component_1/List_with_choice.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/Components/Components.csproj b/Components/Components.csproj index b57c89e..88864a0 100644 --- a/Components/Components.csproj +++ b/Components/Components.csproj @@ -8,4 +8,8 @@ enable + + + + \ No newline at end of file diff --git a/Components/Components.sln b/Components/Components.sln index 865ffa4..e57d51c 100644 --- a/Components/Components.sln +++ b/Components/Components.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.5.33627.172 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Components", "Components.csproj", "{637B2B5F-8015-4DE8-B264-74F24B115812}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Component_1", "..\Component_1\Component_1.csproj", "{9E53BE81-4309-40C4-B6F8-0C80756EE09E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {637B2B5F-8015-4DE8-B264-74F24B115812}.Debug|Any CPU.Build.0 = Debug|Any CPU {637B2B5F-8015-4DE8-B264-74F24B115812}.Release|Any CPU.ActiveCfg = Release|Any CPU {637B2B5F-8015-4DE8-B264-74F24B115812}.Release|Any CPU.Build.0 = Release|Any CPU + {9E53BE81-4309-40C4-B6F8-0C80756EE09E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9E53BE81-4309-40C4-B6F8-0C80756EE09E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9E53BE81-4309-40C4-B6F8-0C80756EE09E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9E53BE81-4309-40C4-B6F8-0C80756EE09E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Components/Form1.Designer.cs b/Components/Form1.Designer.cs index da4a077..5f886be 100644 --- a/Components/Form1.Designer.cs +++ b/Components/Form1.Designer.cs @@ -28,12 +28,30 @@ /// 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"; + list_with_choice1 = new Component_1.List_with_choice(); + SuspendLayout(); + // + // list_with_choice1 + // + list_with_choice1.Element = ""; + list_with_choice1.Location = new Point(131, 60); + list_with_choice1.Name = "list_with_choice1"; + list_with_choice1.Size = new Size(464, 248); + list_with_choice1.TabIndex = 0; + // + // Form1 + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(list_with_choice1); + Name = "Form1"; + Text = "Form1"; + ResumeLayout(false); } #endregion + + private Component_1.List_with_choice list_with_choice1; } } \ No newline at end of file diff --git a/Components/Form1.resx b/Components/Form1.resx index 1af7de1..f298a7b 100644 --- a/Components/Form1.resx +++ b/Components/Form1.resx @@ -1,64 +1,4 @@ - - - +