From 9834f675846c6df50712b66ece8bee2249ea1ca5 Mon Sep 17 00:00:00 2001 From: abazov73 <92822431+abazov73@users.noreply.github.com> Date: Tue, 19 Sep 2023 22:32:09 +0400 Subject: [PATCH] Added checked list box --- AbazovApp/AbazovApp.sln | 6 + AbazovApp/AbazovAppView/AbazovAppView.csproj | 4 + AbazovApp/AbazovAppView/Form1.Designer.cs | 39 ------ AbazovApp/AbazovAppView/Form1.cs | 10 -- AbazovApp/AbazovAppView/Form1.resx | 120 ------------------ AbazovApp/AbazovAppView/FormTest.Designer.cs | 98 ++++++++++++++ AbazovApp/AbazovAppView/FormTest.cs | 48 +++++++ AbazovApp/AbazovAppView/FormTest.resx | 60 +++++++++ AbazovApp/AbazovAppView/Program.cs | 2 +- .../AbazovViewComponents.csproj | 10 ++ .../AbazovCheckedListBox.Designer.cs | 58 +++++++++ .../Components/AbazovCheckedListBox.cs | 52 ++++++++ .../Components/AbazovCheckedListBox.resx | 60 +++++++++ 13 files changed, 397 insertions(+), 170 deletions(-) delete mode 100644 AbazovApp/AbazovAppView/Form1.Designer.cs delete mode 100644 AbazovApp/AbazovAppView/Form1.cs delete mode 100644 AbazovApp/AbazovAppView/Form1.resx create mode 100644 AbazovApp/AbazovAppView/FormTest.Designer.cs create mode 100644 AbazovApp/AbazovAppView/FormTest.cs create mode 100644 AbazovApp/AbazovAppView/FormTest.resx create mode 100644 AbazovApp/AbazovViewComponents/AbazovViewComponents.csproj create mode 100644 AbazovApp/AbazovViewComponents/Components/AbazovCheckedListBox.Designer.cs create mode 100644 AbazovApp/AbazovViewComponents/Components/AbazovCheckedListBox.cs create mode 100644 AbazovApp/AbazovViewComponents/Components/AbazovCheckedListBox.resx diff --git a/AbazovApp/AbazovApp.sln b/AbazovApp/AbazovApp.sln index 46da842..7b91f4c 100644 --- a/AbazovApp/AbazovApp.sln +++ b/AbazovApp/AbazovApp.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.3.32825.248 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbazovAppView", "AbazovAppView\AbazovAppView.csproj", "{D7EF43DC-2F09-4EAD-8161-6D4A08BC7786}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbazovViewComponents", "AbazovViewComponents\AbazovViewComponents.csproj", "{070AAA71-3C9B-4E19-A89D-83372C630C6E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {D7EF43DC-2F09-4EAD-8161-6D4A08BC7786}.Debug|Any CPU.Build.0 = Debug|Any CPU {D7EF43DC-2F09-4EAD-8161-6D4A08BC7786}.Release|Any CPU.ActiveCfg = Release|Any CPU {D7EF43DC-2F09-4EAD-8161-6D4A08BC7786}.Release|Any CPU.Build.0 = Release|Any CPU + {070AAA71-3C9B-4E19-A89D-83372C630C6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {070AAA71-3C9B-4E19-A89D-83372C630C6E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {070AAA71-3C9B-4E19-A89D-83372C630C6E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {070AAA71-3C9B-4E19-A89D-83372C630C6E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/AbazovApp/AbazovAppView/AbazovAppView.csproj b/AbazovApp/AbazovAppView/AbazovAppView.csproj index b57c89e..98fad8c 100644 --- a/AbazovApp/AbazovAppView/AbazovAppView.csproj +++ b/AbazovApp/AbazovAppView/AbazovAppView.csproj @@ -8,4 +8,8 @@ enable + + + + \ No newline at end of file diff --git a/AbazovApp/AbazovAppView/Form1.Designer.cs b/AbazovApp/AbazovAppView/Form1.Designer.cs deleted file mode 100644 index 4530f52..0000000 --- a/AbazovApp/AbazovAppView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace AbazovAppView -{ - 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/AbazovApp/AbazovAppView/Form1.cs b/AbazovApp/AbazovAppView/Form1.cs deleted file mode 100644 index d15553b..0000000 --- a/AbazovApp/AbazovAppView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace AbazovAppView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/AbazovApp/AbazovAppView/Form1.resx b/AbazovApp/AbazovAppView/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/AbazovApp/AbazovAppView/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/AbazovApp/AbazovAppView/FormTest.Designer.cs b/AbazovApp/AbazovAppView/FormTest.Designer.cs new file mode 100644 index 0000000..8e9bb26 --- /dev/null +++ b/AbazovApp/AbazovAppView/FormTest.Designer.cs @@ -0,0 +1,98 @@ +namespace AbazovAppView +{ + partial class FormTest + { + /// + /// 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.abazovCheckedListBox = new AbazovViewComponents.Components.AbazovCheckedListBox(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonClear = new System.Windows.Forms.Button(); + this.buttonSelected = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // abazovCheckedListBox + // + this.abazovCheckedListBox.Location = new System.Drawing.Point(12, 12); + this.abazovCheckedListBox.Name = "abazovCheckedListBox"; + this.abazovCheckedListBox.selectedItem = null; + this.abazovCheckedListBox.Size = new System.Drawing.Size(170, 134); + this.abazovCheckedListBox.TabIndex = 0; + this.abazovCheckedListBox.SelectedItemChange += new System.Action(this.abazovCheckedListBox_SelectedItemChange); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(12, 143); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(150, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonClear + // + this.buttonClear.Location = new System.Drawing.Point(12, 178); + this.buttonClear.Name = "buttonClear"; + this.buttonClear.Size = new System.Drawing.Size(150, 29); + this.buttonClear.TabIndex = 2; + this.buttonClear.Text = "Очистить"; + this.buttonClear.UseVisualStyleBackColor = true; + this.buttonClear.Click += new System.EventHandler(this.buttonClear_Click); + // + // buttonSelected + // + this.buttonSelected.Location = new System.Drawing.Point(12, 213); + this.buttonSelected.Name = "buttonSelected"; + this.buttonSelected.Size = new System.Drawing.Size(150, 48); + this.buttonSelected.TabIndex = 3; + this.buttonSelected.Text = "Выбранный элемент"; + this.buttonSelected.UseVisualStyleBackColor = true; + this.buttonSelected.Click += new System.EventHandler(this.buttonSelected_Click); + // + // FormTest + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonSelected); + this.Controls.Add(this.buttonClear); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.abazovCheckedListBox); + this.Name = "FormTest"; + this.Text = "FormTest"; + this.ResumeLayout(false); + + } + + #endregion + + private AbazovViewComponents.Components.AbazovCheckedListBox abazovCheckedListBox; + private Button buttonAdd; + private Button buttonClear; + private Button buttonSelected; + } +} \ No newline at end of file diff --git a/AbazovApp/AbazovAppView/FormTest.cs b/AbazovApp/AbazovAppView/FormTest.cs new file mode 100644 index 0000000..675d651 --- /dev/null +++ b/AbazovApp/AbazovAppView/FormTest.cs @@ -0,0 +1,48 @@ +using AbazovViewComponents.Components; +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 AbazovAppView +{ + public partial class FormTest : Form + { + public FormTest() + { + InitializeComponent(); + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + Random random = new Random(); + List items = new List(); + for (int i = 0; i < 3; i++) + { + items.Add("item" + random.Next(0, 10000)); + } + abazovCheckedListBox.addItems(items); + abazovCheckedListBox.selectedItem = items[1]; + } + + private void abazovCheckedListBox_SelectedItemChange(string obj) + { + MessageBox.Show(obj, "Select event"); + } + + private void buttonClear_Click(object sender, EventArgs e) + { + abazovCheckedListBox.clear(); + } + + private void buttonSelected_Click(object sender, EventArgs e) + { + MessageBox.Show(abazovCheckedListBox.selectedItem ?? "null", "By getter"); + } + } +} diff --git a/AbazovApp/AbazovAppView/FormTest.resx b/AbazovApp/AbazovAppView/FormTest.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AbazovApp/AbazovAppView/FormTest.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/AbazovApp/AbazovAppView/Program.cs b/AbazovApp/AbazovAppView/Program.cs index 57ced9d..ff97f85 100644 --- a/AbazovApp/AbazovAppView/Program.cs +++ b/AbazovApp/AbazovAppView/Program.cs @@ -11,7 +11,7 @@ namespace AbazovAppView // 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 FormTest()); } } } \ No newline at end of file diff --git a/AbazovApp/AbazovViewComponents/AbazovViewComponents.csproj b/AbazovApp/AbazovViewComponents/AbazovViewComponents.csproj new file mode 100644 index 0000000..060aa1c --- /dev/null +++ b/AbazovApp/AbazovViewComponents/AbazovViewComponents.csproj @@ -0,0 +1,10 @@ + + + + net6.0-windows + enable + true + enable + + + diff --git a/AbazovApp/AbazovViewComponents/Components/AbazovCheckedListBox.Designer.cs b/AbazovApp/AbazovViewComponents/Components/AbazovCheckedListBox.Designer.cs new file mode 100644 index 0000000..df6ff98 --- /dev/null +++ b/AbazovApp/AbazovViewComponents/Components/AbazovCheckedListBox.Designer.cs @@ -0,0 +1,58 @@ +namespace AbazovViewComponents.Components +{ + partial class AbazovCheckedListBox + { + /// + /// Обязательная переменная конструктора. + /// + 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.checkedListBox = new System.Windows.Forms.CheckedListBox(); + this.SuspendLayout(); + // + // checkedListBox + // + this.checkedListBox.FormattingEnabled = true; + this.checkedListBox.Location = new System.Drawing.Point(0, 0); + this.checkedListBox.Name = "checkedListBox"; + this.checkedListBox.Size = new System.Drawing.Size(150, 114); + this.checkedListBox.TabIndex = 0; + this.checkedListBox.SelectedIndexChanged += new System.EventHandler(this.checkedListBox_SelectedIndexChanged); + // + // AbazovCheckedListBox + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.checkedListBox); + this.Name = "AbazovCheckedListBox"; + this.Size = new System.Drawing.Size(150, 115); + this.ResumeLayout(false); + + } + + #endregion + + private CheckedListBox checkedListBox; + } +} diff --git a/AbazovApp/AbazovViewComponents/Components/AbazovCheckedListBox.cs b/AbazovApp/AbazovViewComponents/Components/AbazovCheckedListBox.cs new file mode 100644 index 0000000..f9c9a17 --- /dev/null +++ b/AbazovApp/AbazovViewComponents/Components/AbazovCheckedListBox.cs @@ -0,0 +1,52 @@ +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 AbazovViewComponents.Components +{ + public partial class AbazovCheckedListBox : UserControl + { + public AbazovCheckedListBox() + { + InitializeComponent(); + } + + public string? selectedItem + { + get + { + return checkedListBox.SelectedItem is null ? null : checkedListBox.SelectedItem.ToString(); + } + set + { + checkedListBox.SelectedItem = value; + } + } + + public event Action SelectedItemChange; + + public void addItems(List items) + { + foreach (string item in items) + { + checkedListBox.Items.Add(item); + } + } + + public void clear() + { + checkedListBox.Items.Clear(); + } + + private void checkedListBox_SelectedIndexChanged(object sender, EventArgs e) + { + SelectedItemChange.Invoke(checkedListBox.SelectedItem.ToString()); + } + } +} diff --git a/AbazovApp/AbazovViewComponents/Components/AbazovCheckedListBox.resx b/AbazovApp/AbazovViewComponents/Components/AbazovCheckedListBox.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AbazovApp/AbazovViewComponents/Components/AbazovCheckedListBox.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