Почти сдал

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,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
{
if (CheckRanges(value))
{
numericUpDown.Value = (decimal)value;
}
}
}
private bool CheckRanges(decimal? value)
{
if (MinValue == null || MaxValue == null)
{
error = true;
return;
errorText = "Ошибка, диапазоны не заданы.";
return false;
}
if (value < MinValue || value > MaxValue)
{
error = true;
return;
errorText = "Ошибка, значение не входит в заданный диапазон.";
return false;
}
numericUpDown.Value = value;
}
errorText = "Ошибок нет.";
return true;
}
public event EventHandler DateChanged