From c90b181d85eb3b8286cda748fa215cd77c92642f Mon Sep 17 00:00:00 2001 From: aleyckin Date: Thu, 5 Oct 2023 11:23:18 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D1=87=D1=82=D0=B8=20=D1=81=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WinFormsLibrary/CustomCheckedListBox.cs | 40 ++++++++-------- .../WinFormsLibrary/NumberTextBox.cs | 46 +++++++++++++------ 2 files changed, 52 insertions(+), 34 deletions(-) diff --git a/WinFormsProject/WinFormsLibrary/CustomCheckedListBox.cs b/WinFormsProject/WinFormsLibrary/CustomCheckedListBox.cs index 96cea6e..239eedf 100644 --- a/WinFormsProject/WinFormsLibrary/CustomCheckedListBox.cs +++ b/WinFormsProject/WinFormsLibrary/CustomCheckedListBox.cs @@ -11,6 +11,7 @@ using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace WinFormsLibrary { + public partial class CustomCheckedListBox : UserControl { public CustomCheckedListBox() @@ -18,42 +19,41 @@ namespace WinFormsLibrary InitializeComponent(); } - //метод для очистки public void Clear() { checkedListBox.Items.Clear(); } - //метод для заполнения - public void FillCheckedListBox(List items) - { - checkedListBox.Items.Clear(); - checkedListBox.Items.AddRange(items.ToArray()); - } - - //публичное свойство - public string Selected + public CheckedListBox.ObjectCollection Items { get { - if (checkedListBox.SelectedItems.Count == 0) + return checkedListBox.Items; + } + } + + public string Selected + { + get + { + if (checkedListBox.SelectedItem != null) + { + return checkedListBox.SelectedItem.ToString(); + } + else { return ""; } - string result = ""; - foreach (object itemChecked in checkedListBox.CheckedItems) - { - result += itemChecked.ToString() + Environment.NewLine; - } - return result; } set { - if (checkedListBox.Items.Contains(value)) + for (int i = 0; i < checkedListBox.Items.Count; ++i) { - checkedListBox.SelectedItem = value; + if (checkedListBox.Items[i].ToString() == value) + { + checkedListBox.SetItemChecked(i, true); + } } - } } diff --git a/WinFormsProject/WinFormsLibrary/NumberTextBox.cs b/WinFormsProject/WinFormsLibrary/NumberTextBox.cs index 8dbb2b1..058bc3c 100644 --- a/WinFormsProject/WinFormsLibrary/NumberTextBox.cs +++ b/WinFormsProject/WinFormsLibrary/NumberTextBox.cs @@ -14,7 +14,7 @@ namespace WinFormsLibrary { public int? maxValue = null; public int? minValue = null; - public bool error = false; + public string errorText = ""; public NumberTextBox() { @@ -44,27 +44,45 @@ namespace WinFormsLibrary } } - public decimal Value + public decimal? Value { - get { return numericUpDown.Value; } + get { + if (CheckRanges(numericUpDown.Value)) + { + return numericUpDown.Value; + } + else + { + return null; + } + } set { - if (MinValue == null || MaxValue == null) + if (CheckRanges(value)) { - error = true; - return; + numericUpDown.Value = (decimal)value; } - - if (value < MinValue || value > MaxValue) - { - error = true; - return; - } - - numericUpDown.Value = value; } } + private bool CheckRanges(decimal? value) + { + if (MinValue == null || MaxValue == null) + { + errorText = "Ошибка, диапазоны не заданы."; + return false; + } + + if (value < MinValue || value > MaxValue) + { + errorText = "Ошибка, значение не входит в заданный диапазон."; + return false; + } + + errorText = "Ошибок нет."; + return true; + } + public event EventHandler DateChanged { add { numericUpDown.ValueChanged += value; }