Compare commits

...

7 Commits
main ... lab1

19 changed files with 1095 additions and 0 deletions

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;
}
}
}

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

@ -0,0 +1,224 @@
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.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;
}
}

99
TestView/Form1.cs Normal file
View File

@ -0,0 +1,99 @@
using ViewComponents.Exeption;
namespace TestView
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonAdd_Click(object sender, EventArgs e)
{
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)
{
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 = "Sample text";
}
private void input_text_ItemChange(string obj)
{
MessageBox.Show(obj, "Ñîáûòèå èçìåíåíèÿ òåêñòà");
}
private void buttonCheck_Click(object sender, EventArgs e)
{
if (input_text.Element == null)
MessageBox.Show(input_text.Error);
else MessageBox.Show(input_text.Element, "×åðåç ñâîéñòâî");
}
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"));
myTreeView.addItem(new Book("Ôàíòàñòèêà", "Ðîóëèíã", "Ãàððè Ïîòòåð"));
}
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 = 1;
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}

60
TestView/Form1.resx Normal file
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>

17
TestView/Program.cs Normal file
View File

@ -0,0 +1,17 @@
namespace TestView
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
}

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>

31
TestView/TestView.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33627.172
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestView", "TestView.csproj", "{637B2B5F-8015-4DE8-B264-74F24B115812}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ViewComponents", "..\ViewComponents\ViewComponents.csproj", "{45A652EE-B79B-4F5B-BB2A-2A51F5BEA2F1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{637B2B5F-8015-4DE8-B264-74F24B115812}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
{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
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C28CD353-C746-4FFE-9D0D-D48764205D7B}
EndGlobalSection
EndGlobal

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,65 @@
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 String Error { get; set; } = String.Empty;
public event Action<string?> ItemChange;
public int MinLen { get; set; } = -1;
public int MaxLen { get; set; } = -1;
public string? Element
{
get
{
if (CheckValue()) return textBox1.Text;
return null;
}
set
{
if (MinLen >= 0 && MaxLen >= 0 && value != null && value.Length >= MinLen && value.Length <= MaxLen) textBox1.Text = value;
}
}
public bool CheckValue()
{
Error = string.Empty;
if (MinLen < 0 || MaxLen < 0)
{
Error = "Bounds error";
return false;
}
if (textBox1.Text.Length < MinLen || textBox1.Text.Length > MaxLen)
{
Error = "Value error";
return false;
}
return true;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
ItemChange?.Invoke(textBox1.Text);
}
}
}

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

@ -0,0 +1,58 @@
namespace ViewComponents
{
partial class List_with_choice
{
/// <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()
{
checkedListBox1 = new CheckedListBox();
SuspendLayout();
//
// checkedListBox1
//
checkedListBox1.Dock = DockStyle.Fill;
checkedListBox1.FormattingEnabled = true;
checkedListBox1.Location = new Point(0, 0);
checkedListBox1.Name = "checkedListBox1";
checkedListBox1.Size = new Size(208, 150);
checkedListBox1.TabIndex = 0;
checkedListBox1.SelectedIndexChanged += checkedListBox1_SelectedIndexChanged;
//
// List_with_choice
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(checkedListBox1);
Name = "List_with_choice";
Size = new Size(208, 150);
ResumeLayout(false);
}
#endregion
private CheckedListBox checkedListBox1;
}
}

View File

@ -0,0 +1,56 @@
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)
{
return;
}
checkedListBox1.Items.Add(str);
}
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) throw new ArgumentException();
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 (T)item;
}
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

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Compile Update="Input_text.cs">
<SubType>UserControl</SubType>
<CustomToolNamespace>TestView</CustomToolNamespace>
</Compile>
</ItemGroup>
</Project>