diff --git a/WinFormsProject/WinFormsLibrary/Class1.cs b/WinFormsProject/WinFormsLibrary/Class1.cs new file mode 100644 index 0000000..12a7350 --- /dev/null +++ b/WinFormsProject/WinFormsLibrary/Class1.cs @@ -0,0 +1,6 @@ +namespace WinFormsLibrary +{ + public class Class1 + { + } +} \ No newline at end of file diff --git a/WinFormsProject/WinFormsLibrary/CustomCheckedListBox.Designer.cs b/WinFormsProject/WinFormsLibrary/CustomCheckedListBox.Designer.cs new file mode 100644 index 0000000..67da478 --- /dev/null +++ b/WinFormsProject/WinFormsLibrary/CustomCheckedListBox.Designer.cs @@ -0,0 +1,58 @@ +namespace WinFormsLibrary +{ + partial class CustomCheckedListBox + { + /// + /// Обязательная переменная конструктора. + /// + 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(31, 16); + this.checkedListBox.Name = "checkedListBox"; + this.checkedListBox.Size = new System.Drawing.Size(262, 94); + this.checkedListBox.TabIndex = 0; + this.checkedListBox.SelectedValueChanged += new System.EventHandler(this.checkedListBox_SelectedValueChanged); + // + // CustomCheckedListBox + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.checkedListBox); + this.Name = "CustomCheckedListBox"; + this.Size = new System.Drawing.Size(333, 141); + this.ResumeLayout(false); + + } + + #endregion + + private CheckedListBox checkedListBox; + } +} diff --git a/WinFormsProject/WinFormsLibrary/CustomCheckedListBox.cs b/WinFormsProject/WinFormsLibrary/CustomCheckedListBox.cs new file mode 100644 index 0000000..96cea6e --- /dev/null +++ b/WinFormsProject/WinFormsLibrary/CustomCheckedListBox.cs @@ -0,0 +1,78 @@ +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 static System.Windows.Forms.VisualStyles.VisualStyleElement; + +namespace WinFormsLibrary +{ + public partial class CustomCheckedListBox : UserControl + { + public CustomCheckedListBox() + { + InitializeComponent(); + } + + //метод для очистки + public void Clear() + { + checkedListBox.Items.Clear(); + } + + //метод для заполнения + public void FillCheckedListBox(List items) + { + checkedListBox.Items.Clear(); + checkedListBox.Items.AddRange(items.ToArray()); + } + + //публичное свойство + public string Selected + { + get + { + if (checkedListBox.SelectedItems.Count == 0) + { + return ""; + } + string result = ""; + foreach (object itemChecked in checkedListBox.CheckedItems) + { + result += itemChecked.ToString() + Environment.NewLine; + } + return result; + } + set + { + if (checkedListBox.Items.Contains(value)) + { + checkedListBox.SelectedItem = value; + } + + } + } + + private EventHandler onValueChanged; + public event EventHandler ValueChanged + { + add + { + onValueChanged += value; + } + remove + { + onValueChanged -= value; + } + } + + private void checkedListBox_SelectedValueChanged(object sender, EventArgs e) + { + onValueChanged?.Invoke(sender, e); + } + } +} diff --git a/WinFormsProject/WinFormsLibrary/CustomCheckedListBox.resx b/WinFormsProject/WinFormsLibrary/CustomCheckedListBox.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/WinFormsProject/WinFormsLibrary/CustomCheckedListBox.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/WinFormsProject/WinFormsLibrary/NumberTextBox.Designer.cs b/WinFormsProject/WinFormsLibrary/NumberTextBox.Designer.cs new file mode 100644 index 0000000..9796547 --- /dev/null +++ b/WinFormsProject/WinFormsLibrary/NumberTextBox.Designer.cs @@ -0,0 +1,45 @@ +namespace WinFormsLibrary +{ + partial class NumberTextBox + { + /// + /// Обязательная переменная конструктора. + /// + 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.SuspendLayout(); + // + // NumberTextBox + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Name = "NumberTextBox"; + this.Size = new System.Drawing.Size(364, 264); + this.ResumeLayout(false); + + } + + #endregion + } +} diff --git a/WinFormsProject/WinFormsLibrary/NumberTextBox.cs b/WinFormsProject/WinFormsLibrary/NumberTextBox.cs new file mode 100644 index 0000000..05b2902 --- /dev/null +++ b/WinFormsProject/WinFormsLibrary/NumberTextBox.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 WinFormsLibrary +{ + public partial class NumberTextBox : UserControl + { + public NumberTextBox() + { + InitializeComponent(); + } + } +} diff --git a/WinFormsProject/WinFormsLibrary/NumberTextBox.resx b/WinFormsProject/WinFormsLibrary/NumberTextBox.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/WinFormsProject/WinFormsLibrary/NumberTextBox.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/WinFormsProject/WinFormsLibrary/WinFormsLibrary.csproj b/WinFormsProject/WinFormsLibrary/WinFormsLibrary.csproj new file mode 100644 index 0000000..060aa1c --- /dev/null +++ b/WinFormsProject/WinFormsLibrary/WinFormsLibrary.csproj @@ -0,0 +1,10 @@ + + + + net6.0-windows + enable + true + enable + + + diff --git a/WinFormsProject/WinFormsProject.sln b/WinFormsProject/WinFormsProject.sln new file mode 100644 index 0000000..de4a0d7 --- /dev/null +++ b/WinFormsProject/WinFormsProject.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32819.101 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsProject", "WinFormsProject\WinFormsProject.csproj", "{1FC6ABE3-DF27-453A-B2EE-FA17C71C9CF0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsLibrary", "WinFormsLibrary\WinFormsLibrary.csproj", "{CF6B5601-DC60-48A2-8BDC-1CE32E3F6F15}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1FC6ABE3-DF27-453A-B2EE-FA17C71C9CF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1FC6ABE3-DF27-453A-B2EE-FA17C71C9CF0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1FC6ABE3-DF27-453A-B2EE-FA17C71C9CF0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1FC6ABE3-DF27-453A-B2EE-FA17C71C9CF0}.Release|Any CPU.Build.0 = Release|Any CPU + {CF6B5601-DC60-48A2-8BDC-1CE32E3F6F15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CF6B5601-DC60-48A2-8BDC-1CE32E3F6F15}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CF6B5601-DC60-48A2-8BDC-1CE32E3F6F15}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CF6B5601-DC60-48A2-8BDC-1CE32E3F6F15}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2774D1CA-C461-4F94-89BF-C2FD28AC4024} + EndGlobalSection +EndGlobal diff --git a/WinFormsProject/WinFormsProject/Form1.Designer.cs b/WinFormsProject/WinFormsProject/Form1.Designer.cs new file mode 100644 index 0000000..ff9ac99 --- /dev/null +++ b/WinFormsProject/WinFormsProject/Form1.Designer.cs @@ -0,0 +1,97 @@ +namespace WinFormsProject +{ + 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.customCheckedListBox1 = new WinFormsLibrary.CustomCheckedListBox(); + this.Button_Fill = new System.Windows.Forms.Button(); + this.Button_Clear = new System.Windows.Forms.Button(); + this.Button_GetChosenValues = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // customCheckedListBox1 + // + this.customCheckedListBox1.Location = new System.Drawing.Point(21, 21); + this.customCheckedListBox1.Name = "customCheckedListBox1"; + this.customCheckedListBox1.Selected = ""; + this.customCheckedListBox1.Size = new System.Drawing.Size(333, 141); + this.customCheckedListBox1.TabIndex = 0; + // + // Button_Fill + // + this.Button_Fill.Location = new System.Drawing.Point(130, 141); + this.Button_Fill.Name = "Button_Fill"; + this.Button_Fill.Size = new System.Drawing.Size(106, 45); + this.Button_Fill.TabIndex = 1; + this.Button_Fill.Text = "Заполнить"; + this.Button_Fill.UseVisualStyleBackColor = true; + this.Button_Fill.Click += new System.EventHandler(this.Button_Fill_Click); + // + // Button_Clear + // + this.Button_Clear.Location = new System.Drawing.Point(130, 206); + this.Button_Clear.Name = "Button_Clear"; + this.Button_Clear.Size = new System.Drawing.Size(106, 53); + this.Button_Clear.TabIndex = 2; + this.Button_Clear.Text = "Очистить"; + this.Button_Clear.UseVisualStyleBackColor = true; + this.Button_Clear.Click += new System.EventHandler(this.Button_Clear_Click); + // + // Button_GetChosenValues + // + this.Button_GetChosenValues.Location = new System.Drawing.Point(130, 277); + this.Button_GetChosenValues.Name = "Button_GetChosenValues"; + this.Button_GetChosenValues.Size = new System.Drawing.Size(106, 52); + this.Button_GetChosenValues.TabIndex = 3; + this.Button_GetChosenValues.Text = "Выбранные значения"; + this.Button_GetChosenValues.UseVisualStyleBackColor = true; + this.Button_GetChosenValues.Click += new System.EventHandler(this.Button_GetChosenValues_Click); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.Button_GetChosenValues); + this.Controls.Add(this.Button_Clear); + this.Controls.Add(this.Button_Fill); + this.Controls.Add(this.customCheckedListBox1); + this.Name = "Form1"; + this.Text = "Form1"; + this.ResumeLayout(false); + + } + + #endregion + + private WinFormsLibrary.CustomCheckedListBox customCheckedListBox1; + private Button Button_Fill; + private Button Button_Clear; + private Button Button_GetChosenValues; + } +} \ No newline at end of file diff --git a/WinFormsProject/WinFormsProject/Form1.cs b/WinFormsProject/WinFormsProject/Form1.cs new file mode 100644 index 0000000..42a0b78 --- /dev/null +++ b/WinFormsProject/WinFormsProject/Form1.cs @@ -0,0 +1,41 @@ +namespace WinFormsProject +{ + public partial class Form1 : Form + { + List list = new List { "", "", "" }; + + public Form1() + { + InitializeComponent(); + customCheckedListBox1.FillCheckedListBox(list); + customCheckedListBox1.ValueChanged += CustomEventHandler; + } + + private void CustomEventHandler(object sender, EventArgs e) + { + MessageBox.Show(" ."); + } + + private void Button_Clear_Click(object sender, EventArgs e) + { + customCheckedListBox1.Clear(); + } + + private void Button_Fill_Click(object sender, EventArgs e) + { + customCheckedListBox1.FillCheckedListBox(list); + } + + private void Button_GetChosenValues_Click(object sender, EventArgs e) + { + if (customCheckedListBox1.Selected == null || customCheckedListBox1.Selected == "") + { + MessageBox.Show(" ."); + } + else + { + MessageBox.Show(customCheckedListBox1.Selected); + } + } + } +} \ No newline at end of file diff --git a/WinFormsProject/WinFormsProject/Form1.resx b/WinFormsProject/WinFormsProject/Form1.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/WinFormsProject/WinFormsProject/Form1.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/WinFormsProject/WinFormsProject/Program.cs b/WinFormsProject/WinFormsProject/Program.cs new file mode 100644 index 0000000..cab0e2f --- /dev/null +++ b/WinFormsProject/WinFormsProject/Program.cs @@ -0,0 +1,17 @@ +namespace WinFormsProject +{ + 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/WinFormsProject/WinFormsProject/WinFormsProject.csproj b/WinFormsProject/WinFormsProject/WinFormsProject.csproj new file mode 100644 index 0000000..0654708 --- /dev/null +++ b/WinFormsProject/WinFormsProject/WinFormsProject.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + \ No newline at end of file