готово\

This commit is contained in:
Артем Харламов 2023-10-06 02:36:27 +04:00
parent e73a259ccb
commit 5c0fdc3ee1
23 changed files with 899 additions and 245 deletions

View File

@ -1,10 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>

View File

@ -1,125 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Component_1
{
public partial class List_with_choice : UserControl
{
private event EventHandler? _checkedlistChanged;
private event Action? _errorOccured;
public string Error { get; private set; }
public String Element
{
get
{
if (checkedListBox1.SelectedItem != null) return checkedListBox1.SelectedItem.ToString();
else return string.Empty;
}
set
{
checkedListBox1.SelectedItem = value;
}
}
public event EventHandler Checkedlist
{
add { _checkedlistChanged += value; }
remove { _checkedlistChanged -= value; }
}
public event Action AnErrorOccurred
{
add { _errorOccured += value; }
remove { _errorOccured -= value; }
}
public List_with_choice()
{
InitializeComponent();
Error = string.Empty;
}
public void Fill_List(string str) //метод заполнения списка
{
if (str == null)
{
MessageBox.Show("Вы не ввели строку");
return;
}
string[] list = str.Split(' ');
foreach (string s in list)
{
checkedListBox1.Items.Add(s);
}
}
public void Clean_List() //метод очистки списка
{
checkedListBox1.Items.Clear();
}
private void button_Load_Click(object sender, EventArgs e)
{
string value = "";
if (InputBox("Заполнение списка", "Пожалуйста введите строку", ref value) == DialogResult.OK)
{
try
{
Fill_List(value);
_checkedlistChanged?.Invoke(this, e);
}
catch (Exception ex)
{
Error = ex.Message;
_errorOccured?.Invoke();
}
}
}
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
public static DialogResult InputBox(string title, string promptText, ref string value)//диалоговое окно
{
Form form = new Form();
Label label = new Label();
TextBox textBox = new TextBox();
Button buttonOk = new Button();
Button buttonCancel = new Button();
form.Text = title;
label.Text = promptText;
buttonOk.Text = "OK";
buttonCancel.Text = "Cancel";
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;
label.SetBounds(36, 36, 372, 13);
textBox.SetBounds(36, 86, 700, 20);
buttonOk.SetBounds(228, 160, 160, 60);
buttonCancel.SetBounds(400, 160, 160, 60);
label.AutoSize = true;
form.ClientSize = new Size(796, 307);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;
DialogResult dialogResult = form.ShowDialog();
value = textBox.Text;
return dialogResult;
}
private void button_Clean_Click(object sender, EventArgs e)
{
Clean_List();
}
}
}

View File

@ -1,57 +0,0 @@
namespace Components
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
list_with_choice1 = new Component_1.List_with_choice();
SuspendLayout();
//
// list_with_choice1
//
list_with_choice1.Element = "";
list_with_choice1.Location = new Point(131, 60);
list_with_choice1.Name = "list_with_choice1";
list_with_choice1.Size = new Size(464, 248);
list_with_choice1.TabIndex = 0;
//
// Form1
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(list_with_choice1);
Name = "Form1";
Text = "Form1";
ResumeLayout(false);
}
#endregion
private Component_1.List_with_choice list_with_choice1;
}
}

View File

@ -1,10 +0,0 @@
namespace Components
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

29
TestView/Book.cs Normal file
View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestView
{
public class Book
{
public string Genre;
public string Author;
public string Title;
public Book(string Genre, string Author, string Title)
{
this.Genre = Genre;
this.Author = Author;
this.Title = Title;
}
public Book()
{
Genre = string.Empty;
Author = string.Empty;
Title= string.Empty;
}
}
}

226
TestView/Form1.Designer.cs generated Normal file
View File

@ -0,0 +1,226 @@
namespace TestView
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
buttonAdd = new Button();
buttonClear = new Button();
buttonSelect = new Button();
list_with_choice = new ViewComponents.List_with_choice();
input_text = new ViewComponents.Input_text();
buttonDip = new Button();
buttonVal = new Button();
buttonCheck = new Button();
buttonIerarhy = new Button();
buttonAddBook = new Button();
buttonGetValue = new Button();
buttonGetIndex = new Button();
buttonSetIndex = new Button();
myTreeView = new ViewComponents.MyTreeView();
SuspendLayout();
//
// buttonAdd
//
buttonAdd.Location = new Point(25, 137);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(94, 29);
buttonAdd.TabIndex = 1;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += buttonAdd_Click;
//
// buttonClear
//
buttonClear.Location = new Point(163, 137);
buttonClear.Name = "buttonClear";
buttonClear.Size = new Size(94, 29);
buttonClear.TabIndex = 2;
buttonClear.Text = "Очистить";
buttonClear.UseVisualStyleBackColor = true;
buttonClear.Click += buttonClear_Click;
//
// buttonSelect
//
buttonSelect.Location = new Point(60, 172);
buttonSelect.Name = "buttonSelect";
buttonSelect.Size = new Size(163, 29);
buttonSelect.TabIndex = 3;
buttonSelect.Text = "Выбранный элемент";
buttonSelect.UseVisualStyleBackColor = true;
buttonSelect.Click += buttonSelect_Click;
//
// list_with_choice
//
list_with_choice.Element = "";
list_with_choice.Location = new Point(25, 12);
list_with_choice.Name = "list_with_choice";
list_with_choice.Size = new Size(232, 119);
list_with_choice.TabIndex = 4;
list_with_choice.SelectedItemChange += list_with_choice_SelectedItemChange;
//
// 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;
input_text.ItemChange += input_text_ItemChange;
//
// buttonDip
//
buttonDip.Location = new Point(312, 137);
buttonDip.Name = "buttonDip";
buttonDip.Size = new Size(94, 29);
buttonDip.TabIndex = 6;
buttonDip.Text = "Диапазон";
buttonDip.UseVisualStyleBackColor = true;
buttonDip.Click += buttonDip_Click;
//
// buttonVal
//
buttonVal.Location = new Point(458, 137);
buttonVal.Name = "buttonVal";
buttonVal.Size = new Size(94, 29);
buttonVal.TabIndex = 7;
buttonVal.Text = "Значение";
buttonVal.UseVisualStyleBackColor = true;
buttonVal.Click += buttonVal_Click;
//
// buttonCheck
//
buttonCheck.Location = new Point(360, 172);
buttonCheck.Name = "buttonCheck";
buttonCheck.Size = new Size(143, 29);
buttonCheck.TabIndex = 8;
buttonCheck.Text = " Проверка текста";
buttonCheck.UseVisualStyleBackColor = true;
buttonCheck.Click += buttonCheck_Click;
//
// buttonIerarhy
//
buttonIerarhy.Location = new Point(652, 32);
buttonIerarhy.Name = "buttonIerarhy";
buttonIerarhy.Size = new Size(168, 29);
buttonIerarhy.TabIndex = 10;
buttonIerarhy.Text = "Задать иерархию";
buttonIerarhy.UseVisualStyleBackColor = true;
buttonIerarhy.Click += buttonIerarhy_Click;
//
// buttonAddBook
//
buttonAddBook.Location = new Point(652, 67);
buttonAddBook.Name = "buttonAddBook";
buttonAddBook.Size = new Size(168, 29);
buttonAddBook.TabIndex = 11;
buttonAddBook.Text = "Добавить книги";
buttonAddBook.UseVisualStyleBackColor = true;
buttonAddBook.Click += buttonAddBook_Click;
//
// buttonGetValue
//
buttonGetValue.Location = new Point(652, 102);
buttonGetValue.Name = "buttonGetValue";
buttonGetValue.Size = new Size(168, 29);
buttonGetValue.TabIndex = 12;
buttonGetValue.Text = "Получить значение";
buttonGetValue.UseVisualStyleBackColor = true;
buttonGetValue.Click += buttonGetValue_Click;
//
// buttonGetIndex
//
buttonGetIndex.Location = new Point(652, 137);
buttonGetIndex.Name = "buttonGetIndex";
buttonGetIndex.Size = new Size(168, 29);
buttonGetIndex.TabIndex = 13;
buttonGetIndex.Text = "Получить индекс";
buttonGetIndex.UseVisualStyleBackColor = true;
buttonGetIndex.Click += buttonGetIndex_Click;
//
// buttonSetIndex
//
buttonSetIndex.Location = new Point(652, 172);
buttonSetIndex.Name = "buttonSetIndex";
buttonSetIndex.Size = new Size(168, 29);
buttonSetIndex.TabIndex = 14;
buttonSetIndex.Text = "Установить индекс";
buttonSetIndex.UseVisualStyleBackColor = true;
buttonSetIndex.Click += buttonSetIndex_Click;
//
// myTreeView
//
myTreeView.Location = new Point(629, 218);
myTreeView.Name = "myTreeView";
myTreeView.SelectedNodeIndex = -1;
myTreeView.Size = new Size(226, 204);
myTreeView.TabIndex = 8;
//
// Form1
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(909, 450);
Controls.Add(myTreeView);
Controls.Add(buttonSetIndex);
Controls.Add(buttonGetIndex);
Controls.Add(buttonGetValue);
Controls.Add(buttonAddBook);
Controls.Add(buttonIerarhy);
Controls.Add(buttonCheck);
Controls.Add(buttonVal);
Controls.Add(buttonDip);
Controls.Add(input_text);
Controls.Add(list_with_choice);
Controls.Add(buttonSelect);
Controls.Add(buttonClear);
Controls.Add(buttonAdd);
Name = "Form1";
Text = "Form1";
Load += Form1_Load;
ResumeLayout(false);
}
#endregion
private Button buttonAdd;
private Button buttonClear;
private Button buttonSelect;
private ViewComponents.List_with_choice list_with_choice;
private ViewComponents.Input_text input_text;
private Button buttonDip;
private Button buttonVal;
private Button buttonCheck;
private Button buttonIerarhy;
private Button buttonAddBook;
private Button buttonGetValue;
private Button buttonGetIndex;
private Button buttonSetIndex;
private ViewComponents.MyTreeView myTreeView;
}
}

106
TestView/Form1.cs Normal file
View File

@ -0,0 +1,106 @@
using ViewComponents.Exeption;
namespace TestView
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonAdd_Click(object sender, EventArgs e)
{
string str = "ïåðâûé âòîðîé òðåòèé ÷åòâ¸ðòûé";
list_with_choice.Fill_List(str);
list_with_choice.Element = "ïåðâûé";
}
private void buttonClear_Click(object sender, EventArgs e)
{
list_with_choice.Clean_List();
}
private void buttonSelect_Click(object sender, EventArgs e)
{
MessageBox.Show(list_with_choice.Element ?? "null", "Âûáðàííûé ýëåìåíò");
}
private void list_with_choice_SelectedItemChange(string obj)
{
MessageBox.Show(obj, "Ñîáûòèå âûáîðà ýëåìåíòà");
}
private void buttonDip_Click(object sender, EventArgs e)
{
input_text.MinLen = 5;
input_text.MaxLen = 25;
MessageBox.Show($"Min: {input_text.minlen}; Max: {input_text.maxlen}");
}
private void buttonVal_Click(object sender, EventArgs e)
{
input_text.Element = "Ïðîâåðêà";
}
private void input_text_ItemChange(string obj)
{
MessageBox.Show(obj, "Ñîáûòèå èçìåíåíèÿ òåêñòà");
}
private void buttonCheck_Click(object sender, EventArgs e)
{
try
{
string val = input_text.Element;
MessageBox.Show(val, "×åðåç ñâîéñòâî");
}
catch (TextBoundsNotSetExeption ex)
{
MessageBox.Show(ex.Message);
}
catch (TextOutOfBoundsExeption ex)
{
MessageBox.Show(ex.Message);
}
}
private void buttonIerarhy_Click(object sender, EventArgs e)
{
myTreeView.setHierarchy(new List<(string, bool)> { ("Genre", false), ("Author", false), ("Title", true) });
MessageBox.Show("Èåðàðõèÿ çàäàíà");
}
private void buttonAddBook_Click(object sender, EventArgs e)
{
myTreeView.addItem(new Book("Ðîìàí", "Ãîãîëü Í.Â.", "̸ðòâûå äóøè"));
myTreeView.addItem(new Book("Ðîìàí", "Òóðãåíåâ È.Ñ.", "Îòöû è äåòè"));
myTreeView.addItem(new Book("Ôàíòàñòèêà", "Äæîðäæ Îðóýëë", "1984"));
}
private void buttonGetValue_Click(object sender, EventArgs e)
{
Book? book = myTreeView.getSelecetedNodeValue<Book>();
if (book == null) return;
MessageBox.Show("Æàíð: " + book.Genre + ", Àâòîð: " + book.Author + ", Íàçâàíèå: " + book.Title);
}
private void buttonGetIndex_Click(object sender, EventArgs e)
{
MessageBox.Show(myTreeView.SelectedNodeIndex.ToString());
}
private void buttonSetIndex_Click(object sender, EventArgs e)
{
myTreeView.SelectedNodeIndex = 0;
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}

View File

@ -1,4 +1,4 @@
namespace Components
namespace TestView
{
internal static class Program
{

22
TestView/TestView.csproj Normal file
View File

@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>TestView</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ViewComponents\ViewComponents.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Program.cs">
<CustomToolNamespace></CustomToolNamespace>
</Compile>
</ItemGroup>
</Project>

View File

@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33627.172
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Components", "Components.csproj", "{637B2B5F-8015-4DE8-B264-74F24B115812}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestView", "TestView.csproj", "{637B2B5F-8015-4DE8-B264-74F24B115812}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Component_1", "..\Component_1\Component_1.csproj", "{9E53BE81-4309-40C4-B6F8-0C80756EE09E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ViewComponents", "..\ViewComponents\ViewComponents.csproj", "{45A652EE-B79B-4F5B-BB2A-2A51F5BEA2F1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -17,10 +17,10 @@ Global
{637B2B5F-8015-4DE8-B264-74F24B115812}.Debug|Any CPU.Build.0 = Debug|Any CPU
{637B2B5F-8015-4DE8-B264-74F24B115812}.Release|Any CPU.ActiveCfg = Release|Any CPU
{637B2B5F-8015-4DE8-B264-74F24B115812}.Release|Any CPU.Build.0 = Release|Any CPU
{9E53BE81-4309-40C4-B6F8-0C80756EE09E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9E53BE81-4309-40C4-B6F8-0C80756EE09E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E53BE81-4309-40C4-B6F8-0C80756EE09E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E53BE81-4309-40C4-B6F8-0C80756EE09E}.Release|Any CPU.Build.0 = Release|Any CPU
{45A652EE-B79B-4F5B-BB2A-2A51F5BEA2F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{45A652EE-B79B-4F5B-BB2A-2A51F5BEA2F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45A652EE-B79B-4F5B-BB2A-2A51F5BEA2F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45A652EE-B79B-4F5B-BB2A-2A51F5BEA2F1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace ViewComponents.Exeption
{
[Serializable]
public class TextBoundsNotSetExeption: ApplicationException
{
public TextBoundsNotSetExeption() : base() { }
public TextBoundsNotSetExeption(string message) : base(message) { }
public TextBoundsNotSetExeption(string message, Exception exception) : base(message, exception) { }
protected TextBoundsNotSetExeption(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace ViewComponents.Exeption
{
[Serializable]
public class TextOutOfBoundsExeption: ApplicationException
{
public TextOutOfBoundsExeption() : base() { }
public TextOutOfBoundsExeption(string message) : base(message) { }
public TextOutOfBoundsExeption(string message, Exception exception) : base(message, exception) { }
protected TextOutOfBoundsExeption(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}
}

58
ViewComponents/Input_text.Designer.cs generated Normal file
View File

@ -0,0 +1,58 @@
namespace ViewComponents
{
partial class Input_text
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
textBox1 = new TextBox();
SuspendLayout();
//
// textBox1
//
textBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
textBox1.Location = new Point(19, 25);
textBox1.Name = "textBox1";
textBox1.Size = new Size(154, 27);
textBox1.TabIndex = 0;
textBox1.TextChanged += textBox1_TextChanged;
//
// Input_text
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(textBox1);
Name = "Input_text";
Size = new Size(192, 79);
ResumeLayout(false);
PerformLayout();
}
#endregion
private TextBox textBox1;
}
}

View File

@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ViewComponents.Exeption;
namespace ViewComponents
{
public partial class Input_text : UserControl
{
public Input_text()
{
InitializeComponent();
}
public event Action<string?> ItemChange;
private bool isMin = false;
private bool isMax = false;
public int? minlen;
public int? maxlen;
public string? Element
{
get
{
if (!isMax || !isMin) throw new TextBoundsNotSetExeption("Диапазон не задан");
if(textBox1.Text.Length < minlen || textBox1.Text.Length > maxlen) throw new TextOutOfBoundsExeption("Слово не из диапазона");
return textBox1.Text;
}
set
{
if (isMin && isMax && 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)
{
ItemChange?.Invoke(textBox1.Text);
}
}
}

View File

@ -1,4 +1,4 @@
namespace Component_1
namespace ViewComponents
{
partial class List_with_choice
{
@ -29,58 +29,30 @@
private void InitializeComponent()
{
checkedListBox1 = new CheckedListBox();
button_Load = new Button();
button_Clean = new Button();
SuspendLayout();
//
// checkedListBox1
//
checkedListBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
checkedListBox1.Dock = DockStyle.Fill;
checkedListBox1.FormattingEnabled = true;
checkedListBox1.Location = new Point(85, 23);
checkedListBox1.Location = new Point(0, 0);
checkedListBox1.Name = "checkedListBox1";
checkedListBox1.Size = new Size(201, 92);
checkedListBox1.Size = new Size(208, 150);
checkedListBox1.TabIndex = 0;
checkedListBox1.SelectedIndexChanged += checkedListBox1_SelectedIndexChanged;
//
// button_Load
//
button_Load.Anchor = AnchorStyles.Bottom;
button_Load.Location = new Point(6, 146);
button_Load.Name = "button_Load";
button_Load.Size = new Size(161, 29);
button_Load.TabIndex = 1;
button_Load.Text = "Заполнить список";
button_Load.UseVisualStyleBackColor = true;
button_Load.Click += button_Load_Click;
//
// button_Clean
//
button_Clean.Anchor = AnchorStyles.Bottom;
button_Clean.Location = new Point(203, 146);
button_Clean.Name = "button_Clean";
button_Clean.Size = new Size(153, 29);
button_Clean.TabIndex = 2;
button_Clean.Text = "Очистить список";
button_Clean.UseVisualStyleBackColor = true;
button_Clean.Click += button_Clean_Click;
//
// List_with_choice
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(button_Clean);
Controls.Add(button_Load);
Controls.Add(checkedListBox1);
Name = "List_with_choice";
Size = new Size(371, 198);
Size = new Size(208, 150);
ResumeLayout(false);
}
#endregion
private CheckedListBox checkedListBox1;
private Button button_Load;
private Button button_Clean;
}
}

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ViewComponents
{
public partial class List_with_choice : UserControl
{
public List_with_choice()
{
InitializeComponent();
}
public event Action<string?> SelectedItemChange;
public string? Element
{
get
{
if (checkedListBox1.SelectedItem != null) return checkedListBox1.SelectedItem.ToString();
else return string.Empty;
}
set
{
if (value != null && checkedListBox1.Items.Contains(value)) checkedListBox1.SelectedItem = value;
}
}
public void Fill_List(string str) //метод заполнения списка
{
if (str == null)
{
MessageBox.Show("Вы не ввели строку");
return;
}
string[] list = str.Split(' ');
foreach (string s in list)
{
checkedListBox1.Items.Add(s);
}
}
public void Clean_List() //метод очистки списка
{
checkedListBox1.Items.Clear();
}
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedItemChange?.Invoke(checkedListBox1.SelectedItem.ToString());
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

55
ViewComponents/MyTreeView.Designer.cs generated Normal file
View File

@ -0,0 +1,55 @@
namespace ViewComponents
{
partial class MyTreeView
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
treeView = new TreeView();
SuspendLayout();
//
// treeView
//
treeView.Location = new Point(13, 18);
treeView.Name = "treeView";
treeView.Size = new Size(176, 148);
treeView.TabIndex = 0;
//
// MyTreeView
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(treeView);
Name = "MyTreeView";
Size = new Size(204, 192);
ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TreeView treeView;
}
}

View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace ViewComponents
{
public partial class MyTreeView : UserControl
{
public MyTreeView()
{
InitializeComponent();
}
private List<(string, bool)> hierarchy = new List<(string, bool)>();
public int SelectedNodeIndex
{
get
{
return treeView.SelectedNode?.Index ?? -1;
}
set
{
if (treeView.SelectedNode == null) treeView.SelectedNode = value >= 0 && value < treeView.Nodes.Count ? treeView.Nodes[value] : treeView.SelectedNode;
else treeView.SelectedNode = value >= 0 && value < treeView.SelectedNode.Nodes.Count ? treeView.SelectedNode.Nodes[value] : treeView.SelectedNode;
}
}
public T? getSelecetedNodeValue<T>()
{
if (treeView.SelectedNode == null || treeView.SelectedNode.Nodes.Count > 0) return default(T);
TreeNode? node = treeView.SelectedNode;
var type = typeof(T);
var fields = type.GetFields();
var item = Activator.CreateInstance(type);
while (node != null)
{
var field = fields.FirstOrDefault(x => x.Name == node.Name);
if (field != null)
{
field.SetValue(item, node.Text);
}
node = node.Parent;
}
return item != null ? (T)item : default(T);
}
public void setHierarchy(List<(string, bool)> fields)
{
hierarchy = fields;
}
public void addItem<T>(T item)
{
var type = typeof(T);
var fields = type.GetFields();
TreeNodeCollection nodes = treeView.Nodes;
for (int i = 0; i < hierarchy.Count; i++)
{
var field = fields.FirstOrDefault(x => x.Name.Equals(hierarchy[i].Item1));
if (field is not null)
{
var node = nodes.Find(field.Name, false).FirstOrDefault(x => x.Text == field.GetValue(item).ToString());
if (node is not null && !hierarchy[i].Item2)
{
nodes = node.Nodes;
}
else
{
TreeNode newNode = nodes.Add(field.Name, field.GetValue(item).ToString());
nodes = newNode.Nodes;
}
}
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
@ -9,7 +8,10 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Component_1\Component_1.csproj" />
<Compile Update="Input_text.cs">
<SubType>UserControl</SubType>
<CustomToolNamespace>TestView</CustomToolNamespace>
</Compile>
</ItemGroup>
</Project>
</Project>