diff --git a/TestsComponents/FormTestComponents.Designer.cs b/TestsComponents/FormTestComponents.Designer.cs new file mode 100644 index 0000000..1a00ed9 --- /dev/null +++ b/TestsComponents/FormTestComponents.Designer.cs @@ -0,0 +1,96 @@ +namespace TestsComponents +{ + partial class FormTestComponents + { + /// + /// 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() + { + userCheckedListBox = new WinFormsLibrary1.UserCheckedListBox(); + buttonClear = new Button(); + ButtonShowItems = new Button(); + textBoxItems = new TextBox(); + SuspendLayout(); + // + // userCheckedListBox + // + userCheckedListBox.Location = new Point(0, 0); + userCheckedListBox.Name = "userCheckedListBox"; + userCheckedListBox.SelectedValue = ""; + userCheckedListBox.Size = new Size(263, 170); + userCheckedListBox.TabIndex = 0; + userCheckedListBox.SelectedValueChanged += UserCheckedListBox_SelectedValueChanged; + // + // buttonClear + // + buttonClear.Location = new Point(0, 176); + buttonClear.Name = "buttonClear"; + buttonClear.Size = new Size(263, 29); + buttonClear.TabIndex = 2; + buttonClear.Text = "Очистить"; + buttonClear.UseVisualStyleBackColor = true; + buttonClear.Click += buttonClear_Click; + // + // ButtonShowItems + // + ButtonShowItems.Location = new Point(0, 211); + ButtonShowItems.Name = "ButtonShowItems"; + ButtonShowItems.Size = new Size(263, 29); + ButtonShowItems.TabIndex = 3; + ButtonShowItems.Text = "Показать"; + ButtonShowItems.UseVisualStyleBackColor = true; + ButtonShowItems.Click += ButtonShowItems_Click; + // + // textBoxItems + // + textBoxItems.Location = new Point(0, 246); + textBoxItems.Multiline = true; + textBoxItems.Name = "textBoxItems"; + textBoxItems.Size = new Size(263, 87); + textBoxItems.TabIndex = 4; + // + // FormTestComponents + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(textBoxItems); + Controls.Add(ButtonShowItems); + Controls.Add(buttonClear); + Controls.Add(userCheckedListBox); + Name = "FormTestComponents"; + Text = "FormTestComponents "; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private WinFormsLibrary1.UserCheckedListBox userCheckedListBox; + private Button buttonClear; + private Button ButtonShowItems; + private TextBox textBoxItems; + } +} diff --git a/TestsComponents/FormTestComponents.cs b/TestsComponents/FormTestComponents.cs new file mode 100644 index 0000000..c370512 --- /dev/null +++ b/TestsComponents/FormTestComponents.cs @@ -0,0 +1,29 @@ +namespace TestsComponents +{ + public partial class FormTestComponents : Form + { + public FormTestComponents() + { + InitializeComponent(); + Fill(); + } + public void Fill() + { + userCheckedListBox.append(new() { "items1", "dsdsf", "items3", "fgdg", "iit" }); + } + private void UserCheckedListBox_SelectedValueChanged(object sender, EventArgs e) + { + MessageBox.Show("Selected value changed"); + } + private void buttonClear_Click(object sender, EventArgs e) + { + userCheckedListBox.ClearList(); + } + private void ButtonShowItems_Click(object sender, EventArgs e) + { + + textBoxItems.Text = userCheckedListBox.SelectedValue; + } + + } +} diff --git a/TestsComponents/FormTestComponents.resx b/TestsComponents/FormTestComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TestsComponents/FormTestComponents.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/TestsComponents/Program.cs b/TestsComponents/Program.cs new file mode 100644 index 0000000..16cf020 --- /dev/null +++ b/TestsComponents/Program.cs @@ -0,0 +1,17 @@ +namespace TestsComponents +{ + 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 FormTestComponents()); + } + } +} \ No newline at end of file diff --git a/TestsComponents/TestsComponents.csproj b/TestsComponents/TestsComponents.csproj new file mode 100644 index 0000000..1fd4927 --- /dev/null +++ b/TestsComponents/TestsComponents.csproj @@ -0,0 +1,15 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + \ No newline at end of file diff --git a/WinFormsLibrary1.sln b/WinFormsLibrary1.sln new file mode 100644 index 0000000..00cb6b2 --- /dev/null +++ b/WinFormsLibrary1.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.35027.167 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "COP", "WinFormsLibrary1\COP.csproj", "{2A43B10F-50CB-4768-A95A-2E6B90D0AD41}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestsComponents", "TestsComponents\TestsComponents.csproj", "{C720866B-F5B4-4063-931A-2DB4A35DD888}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2A43B10F-50CB-4768-A95A-2E6B90D0AD41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2A43B10F-50CB-4768-A95A-2E6B90D0AD41}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2A43B10F-50CB-4768-A95A-2E6B90D0AD41}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2A43B10F-50CB-4768-A95A-2E6B90D0AD41}.Release|Any CPU.Build.0 = Release|Any CPU + {C720866B-F5B4-4063-931A-2DB4A35DD888}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C720866B-F5B4-4063-931A-2DB4A35DD888}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C720866B-F5B4-4063-931A-2DB4A35DD888}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C720866B-F5B4-4063-931A-2DB4A35DD888}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5428C310-3E76-48CB-A3D2-14609E3EA213} + EndGlobalSection +EndGlobal diff --git a/WinFormsLibrary1/COP.csproj b/WinFormsLibrary1/COP.csproj new file mode 100644 index 0000000..060aa1c --- /dev/null +++ b/WinFormsLibrary1/COP.csproj @@ -0,0 +1,10 @@ + + + + net6.0-windows + enable + true + enable + + + diff --git a/WinFormsLibrary1/Exceptions/NoRangeException.cs b/WinFormsLibrary1/Exceptions/NoRangeException.cs new file mode 100644 index 0000000..f1958ef --- /dev/null +++ b/WinFormsLibrary1/Exceptions/NoRangeException.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace COP.Exceptions +{ + [Serializable] + public class NoRangeException : ApplicationException + { + public NoRangeException() : base() { } + public NoRangeException(string message) : base(message) { } + public NoRangeException(string message, Exception exception) : base(message, exception) { } + protected NoRangeException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} diff --git a/WinFormsLibrary1/Exceptions/NotIncludedInRangeException.cs b/WinFormsLibrary1/Exceptions/NotIncludedInRangeException.cs new file mode 100644 index 0000000..612f586 --- /dev/null +++ b/WinFormsLibrary1/Exceptions/NotIncludedInRangeException.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace COP.Exceptions +{ + [Serializable] + public class NotIncludedInRangeException: ApplicationException + + { + public NotIncludedInRangeException() : base() { } + public NotIncludedInRangeException(string message) : base(message) { } + public NotIncludedInRangeException(string message, Exception exception) : base(message, exception) { } + protected NotIncludedInRangeException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} diff --git a/WinFormsLibrary1/UserCheckedListBox.Designer.cs b/WinFormsLibrary1/UserCheckedListBox.Designer.cs new file mode 100644 index 0000000..32e6f50 --- /dev/null +++ b/WinFormsLibrary1/UserCheckedListBox.Designer.cs @@ -0,0 +1,57 @@ +namespace WinFormsLibrary1 +{ + partial class UserCheckedListBox + { + /// + /// Обязательная переменная конструктора. + /// + 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.FormattingEnabled = true; + checkedListBox.Location = new Point(0, 0); + checkedListBox.Name = "checkedListBox"; + checkedListBox.Size = new Size(256, 158); + checkedListBox.TabIndex = 0; + checkedListBox.SelectedIndexChanged += CheckedListBox_SelectedIndexChanged; + // + // UserCheckedListBox + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(checkedListBox); + Name = "UserCheckedListBox"; + Size = new Size(257, 155); + ResumeLayout(false); + } + + #endregion + + private CheckedListBox checkedListBox; + } +} diff --git a/WinFormsLibrary1/UserCheckedListBox.cs b/WinFormsLibrary1/UserCheckedListBox.cs new file mode 100644 index 0000000..d9b92f9 --- /dev/null +++ b/WinFormsLibrary1/UserCheckedListBox.cs @@ -0,0 +1,77 @@ +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 WinFormsLibrary1 +{ + public partial class UserCheckedListBox : UserControl + { + private event EventHandler? _selectedValueChanged; + public UserCheckedListBox() + { + InitializeComponent(); + } + public void append(List items) + { + if (items.Count == 0 || items is null) + { + return; + } + + checkedListBox.Items.AddRange(items.ToArray()); + } + public void ClearList() + { + checkedListBox.Items.Clear(); + } + public string SelectedValue + { + get + { + string checkedItems = ""; + for (int i = 0; i < checkedListBox.Items.Count; i++) + { + if (checkedListBox.GetItemChecked(i)) + { + checkedItems += checkedListBox.Items[i].ToString() + " "; + } + } + if (checkedListBox.CheckedItems != null) + return checkedItems; + else + return ""; + } + set + { + for (int i = 0; i < checkedListBox.Items.Count; i++) + { + if (checkedListBox.Items[i].ToString() == value) + { + checkedListBox.SetItemChecked(i, true); + break; + } + } + } + } + + public event EventHandler SelectedValueChanged + { + add { _selectedValueChanged += value; } + remove { _selectedValueChanged += value; } + } + + private void CheckedListBox_SelectedIndexChanged(object sender, EventArgs e) + { + _selectedValueChanged?.Invoke(this, e); + } + + + } + +} diff --git a/WinFormsLibrary1/UserCheckedListBox.resx b/WinFormsLibrary1/UserCheckedListBox.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/WinFormsLibrary1/UserCheckedListBox.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/UserDateTimePickercs.Designer.cs b/WinFormsLibrary1/UserDateTimePickercs.Designer.cs new file mode 100644 index 0000000..900f4a6 --- /dev/null +++ b/WinFormsLibrary1/UserDateTimePickercs.Designer.cs @@ -0,0 +1,56 @@ +namespace COP +{ + partial class UserDateTimePickercs + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + dateTimePicker = new DateTimePicker(); + SuspendLayout(); + // + // dateTimePicker + // + dateTimePicker.Location = new Point(0, 0); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(250, 27); + dateTimePicker.TabIndex = 0; + dateTimePicker.ValueChanged += DateTimePicker_ValueChanged; + // + // UserDateTimePickercs + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(dateTimePicker); + Name = "UserDateTimePickercs"; + Size = new Size(254, 29); + ResumeLayout(false); + } + + #endregion + + private DateTimePicker dateTimePicker; + } +} diff --git a/WinFormsLibrary1/UserDateTimePickercs.cs b/WinFormsLibrary1/UserDateTimePickercs.cs new file mode 100644 index 0000000..b52fa25 --- /dev/null +++ b/WinFormsLibrary1/UserDateTimePickercs.cs @@ -0,0 +1,83 @@ +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 COP.Exceptions; + +namespace COP +{ + public partial class UserDateTimePickercs : UserControl + { + private DateTime? minValue; + private DateTime? maxValue; + + public event EventHandler? _valueChanged; + public UserDateTimePickercs() + { + InitializeComponent(); + + } + public DateTime? MinValue + { + get { return minValue; } + set { minValue = value; } + } + + public DateTime? MaxValue + { + get { return maxValue; } + set { maxValue = value; } + } + public DateTime? SelectedValue + { + get + { + if (!minValue.HasValue || !maxValue.HasValue) + { + throw new NoRangeException("Диапозон не был задан"); + } + else if (dateTimePicker.Value < minValue || + dateTimePicker.Value > maxValue) + { + + return null; + } + + return dateTimePicker.Value; + } + set + { + + if (!minValue.HasValue || !maxValue.HasValue) + { + throw new NoRangeException("Диапозон не был задан"); + } + if (value < minValue || value > maxValue) + { + + throw new NotIncludedInRangeException("Selected value is out of range."); + } + + dateTimePicker.Value = value.Value; + + } + } + public event EventHandler ValueChanged + { + add { _valueChanged += value; } + remove { _valueChanged -= value; } + } + private void DateTimePicker_ValueChanged(object sender, EventArgs e) + { + + + _valueChanged?.Invoke(this, e); + + } + } +} diff --git a/WinFormsLibrary1/UserDateTimePickercs.resx b/WinFormsLibrary1/UserDateTimePickercs.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/WinFormsLibrary1/UserDateTimePickercs.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