Почти сдал

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
{
public partial class CustomCheckedListBox : UserControl
{
public CustomCheckedListBox()
@ -18,42 +19,41 @@ namespace WinFormsLibrary
InitializeComponent();
}
//метод для очистки
public void Clear()
{
checkedListBox.Items.Clear();
}
//метод для заполнения
public void FillCheckedListBox(List<string> items)
public CheckedListBox.ObjectCollection Items
{
checkedListBox.Items.Clear();
checkedListBox.Items.AddRange(items.ToArray());
get
{
return checkedListBox.Items;
}
}
//публичное свойство
public string Selected
{
get
{
if (checkedListBox.SelectedItems.Count == 0)
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);
}
}
}
}

View File

@ -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; }