Почти сдал

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();
checkedListBox.Items.AddRange(items.ToArray());
}
//публичное свойство
public string Selected
{ {
get get
{ {
if (checkedListBox.SelectedItems.Count == 0) return checkedListBox.Items;
}
}
public string Selected
{
get
{
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,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 set
{ {
if (MinValue == null || MaxValue == null) if (CheckRanges(value))
{ {
error = true; numericUpDown.Value = (decimal)value;
return;
} }
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 public event EventHandler DateChanged
{ {
add { numericUpDown.ValueChanged += value; } add { numericUpDown.ValueChanged += value; }