поправка

This commit is contained in:
annalyovushkina@yandex.ru 2024-09-23 12:27:58 +04:00
parent d0b096e308
commit 37673c4961
2 changed files with 32 additions and 67 deletions

View File

@ -17,40 +17,11 @@ namespace KOP_Labs
{
InitializeComponent();
}
private string examp = "Введите текст от " + decimal.MinValue + " до" + decimal.MaxValue + " символов";
public int? max = null;
public int? min = null;
public int? Max
{
get
{
return max;
}
set
{
if (value == null || value <= 0) return;
max = value;
}
}
public int? Min
{
get
{
return min;
}
set
{
if (value == null || value < 0) return;
min = value;
}
}
public int? MinValue { get; set; }
public int? MaxValue { get; set; }
private EventHandler _changeEvent;
public event EventHandler ChangeEvent
{
add
@ -66,41 +37,46 @@ namespace KOP_Labs
private void textBox_TextChanged(object sender, EventArgs e)
{
_changeEvent?.Invoke(sender, e);
}
private void textBox_Enter(object sender, EventArgs e)
if (MinValue != null && MaxValue != null)
{
ToolTip tt = new ToolTip();
tt.Show(examp, textBox, 30, -20, 2000);
if (textBox.Text.Length < MinValue || textBox.Text.Length > MaxValue)
{
textBox.ForeColor = Color.Red;
}
else
{
textBox.ForeColor = Color.Black;
}
}
public string? TextBoxValue
}
public string TextBoxValue
{
get
{
if (Min == null || Max == null)
if (MinValue == null && MaxValue == null)
{
throw new NoBordersException("Границы не заданы");
throw new NoBordersException("Диапазон не задан.");
}
if (textBox.Text.Length < Min || textBox.Text.Length > Max)
if (textBox.Text.Length >= MinValue && textBox.Text.Length <= MaxValue)
{
throw new ArgumentOutOfRangeException("Ваша строка не входит в границы диапозона: " + Min + " - " + Max);
}
return textBox.Text;
}
throw new NoBordersException("Введенное значение не входит в диапазон.");
}
set
{
if (value == null || value.Length < 0 || Max == null)
if (MinValue != null && MaxValue != null)
{
return;
}
if (value.Length < Min && value.Length > Max)
if (value.Length >= MinValue && value.Length <= MaxValue)
{
return;
}
textBox.Text = value;
}
}
}
}
}
}

View File

@ -61,25 +61,14 @@ namespace KOP_Labs
{
get
{
if(checkedListBox.Items.Count == 0)
{
return "";
}
if(checkedListBox.Items.Count == null)
{
return "";
}
return checkedListBox.SelectedItem.ToString()!;
return checkedListBox.SelectedItem?.ToString() ?? string.Empty;
}
set
{
int index = checkedListBox.Items.IndexOf(value);
if (index == -1)
if (checkedListBox.Items.Contains(value))
{
return;
}
checkedListBox.SelectedItem = value;
checkedListBox.SetItemChecked(index, true);
}
}
}