From 26ccde517c2f782935122949c8fd02b6db608b16 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Fri, 6 Sep 2024 12:39:51 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=20=D0=BF=D0=B5=D1=80=D0=B2=D1=8B=D0=B9=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WinFormSolution/Components/Components.csproj | 10 ++ .../UserControlCheckedList.Designer.cs | 60 +++++++++ .../Components/UserControlCheckedList.cs | 59 +++++++++ .../Components/UserControlCheckedList.resx | 120 ++++++++++++++++++ WinFormSolution/WinFormSolution.sln | 31 +++++ WinFormSolution/WinFormsApp/Form.Designer.cs | 83 ++++++++++++ WinFormSolution/WinFormsApp/Form.cs | 28 ++++ WinFormSolution/WinFormsApp/Form.resx | 120 ++++++++++++++++++ WinFormSolution/WinFormsApp/Program.cs | 17 +++ .../WinFormsApp/WinFormsApp.csproj | 15 +++ 10 files changed, 543 insertions(+) create mode 100644 WinFormSolution/Components/Components.csproj create mode 100644 WinFormSolution/Components/UserControlCheckedList.Designer.cs create mode 100644 WinFormSolution/Components/UserControlCheckedList.cs create mode 100644 WinFormSolution/Components/UserControlCheckedList.resx create mode 100644 WinFormSolution/WinFormSolution.sln create mode 100644 WinFormSolution/WinFormsApp/Form.Designer.cs create mode 100644 WinFormSolution/WinFormsApp/Form.cs create mode 100644 WinFormSolution/WinFormsApp/Form.resx create mode 100644 WinFormSolution/WinFormsApp/Program.cs create mode 100644 WinFormSolution/WinFormsApp/WinFormsApp.csproj diff --git a/WinFormSolution/Components/Components.csproj b/WinFormSolution/Components/Components.csproj new file mode 100644 index 0000000..3e210aa --- /dev/null +++ b/WinFormSolution/Components/Components.csproj @@ -0,0 +1,10 @@ + + + + net8.0-windows + enable + true + enable + + + diff --git a/WinFormSolution/Components/UserControlCheckedList.Designer.cs b/WinFormSolution/Components/UserControlCheckedList.Designer.cs new file mode 100644 index 0000000..a074f84 --- /dev/null +++ b/WinFormSolution/Components/UserControlCheckedList.Designer.cs @@ -0,0 +1,60 @@ +namespace Components +{ + partial class UserControlCheckedList + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + checkedListBox = new CheckedListBox(); + SuspendLayout(); + // + // checkedListBox + // + checkedListBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + checkedListBox.CheckOnClick = true; + checkedListBox.FormattingEnabled = true; + checkedListBox.Location = new Point(20, 15); + checkedListBox.Name = "checkedListBox"; + checkedListBox.Size = new Size(276, 148); + checkedListBox.TabIndex = 0; + checkedListBox.ItemCheck += checkedListBox_ItemCheck; + // + // UserControlCheckedList + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + BackColor = Color.Firebrick; + Controls.Add(checkedListBox); + Name = "UserControlCheckedList"; + Size = new Size(318, 183); + ResumeLayout(false); + } + + #endregion + + private CheckedListBox checkedListBox; + } +} diff --git a/WinFormSolution/Components/UserControlCheckedList.cs b/WinFormSolution/Components/UserControlCheckedList.cs new file mode 100644 index 0000000..018025a --- /dev/null +++ b/WinFormSolution/Components/UserControlCheckedList.cs @@ -0,0 +1,59 @@ +namespace Components +{ + public partial class UserControlCheckedList : UserControl + { + private EventHandler _onCheckedItemChangedEvent; + public event EventHandler CheckedItemChanged + { + add + { + _onCheckedItemChangedEvent += value; + } + remove + { + _onCheckedItemChangedEvent -= value; + } + } + public string CheckedItem + { + get + { + return checkedListBox.CheckedItems[0] as string ?? string.Empty; + } + set + { + if (checkedListBox.Items.Contains(value)) + { + checkedListBox.SetItemCheckState(checkedListBox.Items.IndexOf(value), CheckState.Checked); + } + } + } + public UserControlCheckedList() + { + InitializeComponent(); + } + public void SetCheckedListBoxValues(List values) + { + ClearCheckedListBoxValues(); + foreach (var item in values) + { + checkedListBox.Items.Add(item); + } + } + public void ClearCheckedListBoxValues() + { + checkedListBox.Items.Clear(); + } + private void checkedListBox_ItemCheck(object sender, ItemCheckEventArgs e) + { + for (int i = 0; i < checkedListBox.Items.Count; i++) + { + if (i != e.Index) + { + checkedListBox.SetItemChecked(i, false); + } + } + _onCheckedItemChangedEvent?.Invoke(sender, e); + } + } +} diff --git a/WinFormSolution/Components/UserControlCheckedList.resx b/WinFormSolution/Components/UserControlCheckedList.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/WinFormSolution/Components/UserControlCheckedList.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/WinFormSolution/WinFormSolution.sln b/WinFormSolution/WinFormSolution.sln new file mode 100644 index 0000000..91e53fa --- /dev/null +++ b/WinFormSolution/WinFormSolution.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35222.181 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Components", "Components\Components.csproj", "{18A921F6-FEBD-44BE-B74B-693AD384FD65}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsApp", "WinFormsApp\WinFormsApp.csproj", "{B2B2491A-9FAF-4682-B859-CEA0D63E593E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {18A921F6-FEBD-44BE-B74B-693AD384FD65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {18A921F6-FEBD-44BE-B74B-693AD384FD65}.Debug|Any CPU.Build.0 = Debug|Any CPU + {18A921F6-FEBD-44BE-B74B-693AD384FD65}.Release|Any CPU.ActiveCfg = Release|Any CPU + {18A921F6-FEBD-44BE-B74B-693AD384FD65}.Release|Any CPU.Build.0 = Release|Any CPU + {B2B2491A-9FAF-4682-B859-CEA0D63E593E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B2B2491A-9FAF-4682-B859-CEA0D63E593E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B2B2491A-9FAF-4682-B859-CEA0D63E593E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B2B2491A-9FAF-4682-B859-CEA0D63E593E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {431FB736-164C-4849-B179-D048D3651094} + EndGlobalSection +EndGlobal diff --git a/WinFormSolution/WinFormsApp/Form.Designer.cs b/WinFormSolution/WinFormsApp/Form.Designer.cs new file mode 100644 index 0000000..e772409 --- /dev/null +++ b/WinFormSolution/WinFormsApp/Form.Designer.cs @@ -0,0 +1,83 @@ +namespace WinFormsApp +{ + partial class Form + { + /// + /// 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() + { + userControlCheckedList = new Components.UserControlCheckedList(); + buttonFillCheckedList = new Button(); + buttonClearList = new Button(); + SuspendLayout(); + // + // userControlCheckedList + // + userControlCheckedList.BackColor = Color.Firebrick; + userControlCheckedList.Location = new Point(12, 12); + userControlCheckedList.Name = "userControlCheckedList"; + userControlCheckedList.Size = new Size(315, 170); + userControlCheckedList.TabIndex = 0; + // + // buttonFillCheckedList + // + buttonFillCheckedList.Location = new Point(12, 202); + buttonFillCheckedList.Name = "buttonFillCheckedList"; + buttonFillCheckedList.Size = new Size(75, 23); + buttonFillCheckedList.TabIndex = 1; + buttonFillCheckedList.Text = "Заполнить"; + buttonFillCheckedList.UseVisualStyleBackColor = true; + buttonFillCheckedList.Click += buttonFillCheckedList_Click; + // + // buttonClearList + // + buttonClearList.Location = new Point(105, 202); + buttonClearList.Name = "buttonClearList"; + buttonClearList.Size = new Size(75, 23); + buttonClearList.TabIndex = 2; + buttonClearList.Text = "Очистить"; + buttonClearList.UseVisualStyleBackColor = true; + buttonClearList.Click += buttonClearList_Click; + // + // Form + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(697, 459); + Controls.Add(buttonClearList); + Controls.Add(buttonFillCheckedList); + Controls.Add(userControlCheckedList); + Name = "Form"; + Text = "Form"; + ResumeLayout(false); + } + + #endregion + + private Components.UserControlCheckedList userControlCheckedList; + private Button buttonFillCheckedList; + private Button buttonClearList; + } +} diff --git a/WinFormSolution/WinFormsApp/Form.cs b/WinFormSolution/WinFormsApp/Form.cs new file mode 100644 index 0000000..9fa6729 --- /dev/null +++ b/WinFormSolution/WinFormsApp/Form.cs @@ -0,0 +1,28 @@ +namespace WinFormsApp +{ + public partial class Form : System.Windows.Forms.Form + { + public Form() + { + InitializeComponent(); + } + + private void buttonFillCheckedList_Click(object sender, EventArgs e) + { + List list = new List(); + list.Add(""); + list.Add(""); + list.Add(""); + list.Add(""); + list.Add("C#"); + userControlCheckedList.SetCheckedListBoxValues(list); + + userControlCheckedList.CheckedItem = list[3]; + } + + private void buttonClearList_Click(object sender, EventArgs e) + { + userControlCheckedList.ClearCheckedListBoxValues(); + } + } +} diff --git a/WinFormSolution/WinFormsApp/Form.resx b/WinFormSolution/WinFormsApp/Form.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/WinFormSolution/WinFormsApp/Form.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/WinFormSolution/WinFormsApp/Program.cs b/WinFormSolution/WinFormsApp/Program.cs new file mode 100644 index 0000000..e5575f1 --- /dev/null +++ b/WinFormSolution/WinFormsApp/Program.cs @@ -0,0 +1,17 @@ +namespace WinFormsApp +{ + 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 Form()); + } + } +} \ No newline at end of file diff --git a/WinFormSolution/WinFormsApp/WinFormsApp.csproj b/WinFormSolution/WinFormsApp/WinFormsApp.csproj new file mode 100644 index 0000000..4d25b40 --- /dev/null +++ b/WinFormSolution/WinFormsApp/WinFormsApp.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net8.0-windows + enable + true + enable + + + + + + + \ No newline at end of file