поправка
This commit is contained in:
parent
d0b096e308
commit
37673c4961
@ -16,41 +16,12 @@ namespace KOP_Labs
|
|||||||
public CustomComboBox()
|
public CustomComboBox()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
private string examp = "Введите текст от " + decimal.MinValue + " до" + decimal.MaxValue + " символов";
|
public int? MinValue { get; set; }
|
||||||
|
public int? MaxValue { get; set; }
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private EventHandler _changeEvent;
|
private EventHandler _changeEvent;
|
||||||
|
|
||||||
public event EventHandler ChangeEvent
|
public event EventHandler ChangeEvent
|
||||||
{
|
{
|
||||||
add
|
add
|
||||||
@ -66,39 +37,44 @@ namespace KOP_Labs
|
|||||||
private void textBox_TextChanged(object sender, EventArgs e)
|
private void textBox_TextChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
_changeEvent?.Invoke(sender, e);
|
_changeEvent?.Invoke(sender, e);
|
||||||
|
if (MinValue != null && MaxValue != null)
|
||||||
|
{
|
||||||
|
if (textBox.Text.Length < MinValue || textBox.Text.Length > MaxValue)
|
||||||
|
{
|
||||||
|
textBox.ForeColor = Color.Red;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
textBox.ForeColor = Color.Black;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void textBox_Enter(object sender, EventArgs e)
|
public string TextBoxValue
|
||||||
{
|
|
||||||
ToolTip tt = new ToolTip();
|
|
||||||
tt.Show(examp, textBox, 30, -20, 2000);
|
|
||||||
}
|
|
||||||
|
|
||||||
public string? TextBoxValue
|
|
||||||
{
|
{
|
||||||
get
|
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;
|
||||||
}
|
}
|
||||||
return textBox.Text;
|
throw new NoBordersException("Введенное значение не входит в диапазон.");
|
||||||
|
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value == null || value.Length < 0 || Max == null)
|
if (MinValue != null && MaxValue != null)
|
||||||
{
|
{
|
||||||
return;
|
if (value.Length >= MinValue && value.Length <= MaxValue)
|
||||||
|
{
|
||||||
|
textBox.Text = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (value.Length < Min && value.Length > Max)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
textBox.Text = value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,26 +61,15 @@ namespace KOP_Labs
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if(checkedListBox.Items.Count == 0)
|
return checkedListBox.SelectedItem?.ToString() ?? string.Empty;
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
if(checkedListBox.Items.Count == null)
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return checkedListBox.SelectedItem.ToString()!;
|
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
int index = checkedListBox.Items.IndexOf(value);
|
if (checkedListBox.Items.Contains(value))
|
||||||
if (index == -1)
|
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
}
|
|
||||||
checkedListBox.SelectedItem = value;
|
checkedListBox.SelectedItem = value;
|
||||||
checkedListBox.SetItemChecked(index, true);
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user