Почти сдал

This commit is contained in:
aleyckin 2023-10-05 11:23:18 +04:00
parent 5b17be9211
commit c90b181d85
2 changed files with 52 additions and 34 deletions

View File

@ -11,6 +11,7 @@ using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace WinFormsLibrary namespace WinFormsLibrary
{ {
public partial class CustomCheckedListBox : UserControl public partial class CustomCheckedListBox : UserControl
{ {
public CustomCheckedListBox() public CustomCheckedListBox()
@ -18,42 +19,41 @@ namespace WinFormsLibrary
InitializeComponent(); InitializeComponent();
} }
//метод для очистки
public void Clear() public void Clear()
{ {
checkedListBox.Items.Clear(); checkedListBox.Items.Clear();
} }
//метод для заполнения public CheckedListBox.ObjectCollection Items
public void FillCheckedListBox(List<string> items)
{ {
checkedListBox.Items.Clear(); get
checkedListBox.Items.AddRange(items.ToArray()); {
return checkedListBox.Items;
}
} }
//публичное свойство
public string Selected public string Selected
{ {
get get
{ {
if (checkedListBox.SelectedItems.Count == 0) if (checkedListBox.SelectedItem != null)
{
return checkedListBox.SelectedItem.ToString();
}
else
{ {
return ""; return "";
} }
string result = "";
foreach (object itemChecked in checkedListBox.CheckedItems)
{
result += itemChecked.ToString() + Environment.NewLine;
}
return result;
} }
set 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);
}
} }
} }
} }

View File

@ -14,7 +14,7 @@ namespace WinFormsLibrary
{ {
public int? maxValue = null; public int? maxValue = null;
public int? minValue = null; public int? minValue = null;
public bool error = false; public string errorText = "";
public NumberTextBox() public NumberTextBox()
{ {
@ -44,25 +44,43 @@ namespace WinFormsLibrary
} }
} }
public decimal Value public decimal? Value
{ {
get { return numericUpDown.Value; } get {
if (CheckRanges(numericUpDown.Value))
{
return numericUpDown.Value;
}
else
{
return null;
}
}
set set
{
if (CheckRanges(value))
{
numericUpDown.Value = (decimal)value;
}
}
}
private bool CheckRanges(decimal? value)
{ {
if (MinValue == null || MaxValue == null) if (MinValue == null || MaxValue == null)
{ {
error = true; errorText = "Ошибка, диапазоны не заданы.";
return; return false;
} }
if (value < MinValue || value > MaxValue) if (value < MinValue || value > MaxValue)
{ {
error = true; errorText = "Ошибка, значение не входит в заданный диапазон.";
return; return false;
} }
numericUpDown.Value = value; errorText = "Ошибок нет.";
} return true;
} }
public event EventHandler DateChanged public event EventHandler DateChanged