фикс 2-го компонента

This commit is contained in:
Артем Харламов 2023-10-15 20:05:17 +04:00
parent 3b31a57033
commit bee04958e0
4 changed files with 23 additions and 58 deletions

View File

@ -86,8 +86,6 @@
// input_text
//
input_text.Location = new Point(312, 12);
input_text.MaxLen = null;
input_text.MinLen = null;
input_text.Name = "input_text";
input_text.Size = new Size(240, 119);
input_text.TabIndex = 5;

View File

@ -11,10 +11,11 @@ namespace TestView
private void buttonAdd_Click(object sender, EventArgs e)
{
string str = "ïåðâûé âòîðîé òðåòèé ÷åòâ¸ðòûé";
list_with_choice.Fill_List(str);
list_with_choice.Element = "ïåðâûé";
list_with_choice.Fill_List("ïåðâûé");
list_with_choice.Fill_List("âòîðîé");
list_with_choice.Fill_List("òðåòèé");
list_with_choice.Fill_List("÷åòâ¸ðòûé");
}
private void buttonClear_Click(object sender, EventArgs e)
@ -37,12 +38,12 @@ namespace TestView
input_text.MinLen = 5;
input_text.MaxLen = 25;
MessageBox.Show($"Min: {input_text.minlen}; Max: {input_text.maxlen}");
MessageBox.Show($"Min: {input_text.MinLen}; Max: {input_text.MaxLen}");
}
private void buttonVal_Click(object sender, EventArgs e)
{
input_text.Element = "Ïðîâåðêà";
input_text.Element = "Sample text";
}
private void input_text_ItemChange(string obj)
@ -54,8 +55,12 @@ namespace TestView
{
try
{
string val = input_text.Element;
MessageBox.Show(val, "×åðåç ñâîéñòâî");
if (input_text.Element.Equals("Range exeption"))
throw new TextBoundsNotSetExeption("Äèàïàçîí íå çàäàí");
if (input_text.Element.Equals("Value exeption"))
throw new TextOutOfBoundsExeption("Ñëîâî âíå äèàïàçîíà");
MessageBox.Show(input_text.Element, "×åðåç ñâîéñòâî");
}
catch (TextBoundsNotSetExeption ex)
{
@ -96,7 +101,7 @@ namespace TestView
private void buttonSetIndex_Click(object sender, EventArgs e)
{
myTreeView.SelectedNodeIndex = 1;û
myTreeView.SelectedNodeIndex = 1;
}
private void Form1_Load(object sender, EventArgs e)

View File

@ -20,58 +20,25 @@ namespace ViewComponents
}
public event Action<string?> ItemChange;
private bool isMin = false;
private bool isMax = false;
public int? minlen;
public int? maxlen;
public string? Element
public int MinLen { get; set; } = -1;
public int MaxLen { get; set; } = -1;
public string Element
{
get
{
if (!isMax || !isMin) throw new TextBoundsNotSetExeption("Диапазон не задан");
if(textBox1.Text.Length < minlen || textBox1.Text.Length > maxlen) throw new TextOutOfBoundsExeption("Слово не из диапазона");
if (MinLen < 0 || MaxLen < 0) return "Range exeption";
if (textBox1.Text.Length < MinLen || textBox1.Text.Length > MaxLen) return "Value exeption";
return textBox1.Text;
}
set
{
if (isMin && isMax && value != null && value.Length >= minlen && value.Length <= maxlen) textBox1.Text = value;
if (MinLen >= 0 && MaxLen >= 0 && value != null && value.Length >= MinLen && value.Length <= MaxLen) textBox1.Text = value;
}
}
public int? MinLen
{
get
{
if (isMin == true) return minlen;
else return null;
}
set
{
if (value.HasValue)
{
minlen = value;
isMin = true;
}
}
}
public int? MaxLen
{
get
{
if (isMax == true) return maxlen;
else return null;
}
set
{
if (value.HasValue)
{
maxlen = value;
isMax = true;
}
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{

View File

@ -37,15 +37,10 @@ namespace ViewComponents
{
if (str == null)
{
MessageBox.Show("Вы не ввели строку");
return;
}
string[] list = str.Split(' ');
foreach (string s in list)
{
checkedListBox1.Items.Add(s);
}
checkedListBox1.Items.Add(str);
}
public void Clean_List() //метод очистки списка
{