done
This commit is contained in:
parent
9403e65edc
commit
e57bd46f1f
267
WinFormsApp1/Form1.Designer.cs
generated
Normal file
267
WinFormsApp1/Form1.Designer.cs
generated
Normal file
@ -0,0 +1,267 @@
|
||||
namespace WinFormsApp1
|
||||
{
|
||||
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()
|
||||
{
|
||||
customCheckedListBox = new WinFormsLibrary1.CustomCheckedListBox();
|
||||
addInListboxItemButton = new Button();
|
||||
clearListboxButton = new Button();
|
||||
listboxItemValuetextBox = new TextBox();
|
||||
getSelectedItemButton = new Button();
|
||||
selectedItemLabel = new Label();
|
||||
customTextBox = new WinFormsLibrary1.CustomTextBox();
|
||||
errorCustomTextBoxLabel = new Label();
|
||||
checkCustomTextBoxButton = new Button();
|
||||
customDataTree = new WinFormsLibrary1.CustomDataTree();
|
||||
label1 = new Label();
|
||||
nameTextBox = new TextBox();
|
||||
label2 = new Label();
|
||||
positionTextBox = new TextBox();
|
||||
label3 = new Label();
|
||||
addEmployeeButton = new Button();
|
||||
departamentComboBox = new ComboBox();
|
||||
getSelectedTreeItemButton = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// customCheckedListBox
|
||||
//
|
||||
customCheckedListBox.Location = new Point(25, 9);
|
||||
customCheckedListBox.Margin = new Padding(3, 2, 3, 2);
|
||||
customCheckedListBox.Name = "customCheckedListBox";
|
||||
customCheckedListBox.SelectedElement = "";
|
||||
customCheckedListBox.Size = new Size(130, 156);
|
||||
customCheckedListBox.TabIndex = 0;
|
||||
//
|
||||
// addInListboxItemButton
|
||||
//
|
||||
addInListboxItemButton.Location = new Point(175, 35);
|
||||
addInListboxItemButton.Margin = new Padding(3, 2, 3, 2);
|
||||
addInListboxItemButton.Name = "addInListboxItemButton";
|
||||
addInListboxItemButton.Size = new Size(130, 28);
|
||||
addInListboxItemButton.TabIndex = 1;
|
||||
addInListboxItemButton.Text = "Add or select item";
|
||||
addInListboxItemButton.UseVisualStyleBackColor = true;
|
||||
addInListboxItemButton.Click += addInListboxItemButton_Click;
|
||||
//
|
||||
// clearListboxButton
|
||||
//
|
||||
clearListboxButton.Location = new Point(175, 68);
|
||||
clearListboxButton.Margin = new Padding(3, 2, 3, 2);
|
||||
clearListboxButton.Name = "clearListboxButton";
|
||||
clearListboxButton.Size = new Size(130, 28);
|
||||
clearListboxButton.TabIndex = 2;
|
||||
clearListboxButton.Text = "Clear listbox";
|
||||
clearListboxButton.UseVisualStyleBackColor = true;
|
||||
clearListboxButton.Click += clearListboxButton_Click;
|
||||
//
|
||||
// listboxItemValuetextBox
|
||||
//
|
||||
listboxItemValuetextBox.Location = new Point(175, 9);
|
||||
listboxItemValuetextBox.Margin = new Padding(3, 2, 3, 2);
|
||||
listboxItemValuetextBox.Name = "listboxItemValuetextBox";
|
||||
listboxItemValuetextBox.Size = new Size(131, 23);
|
||||
listboxItemValuetextBox.TabIndex = 3;
|
||||
//
|
||||
// getSelectedItemButton
|
||||
//
|
||||
getSelectedItemButton.Location = new Point(175, 125);
|
||||
getSelectedItemButton.Margin = new Padding(3, 2, 3, 2);
|
||||
getSelectedItemButton.Name = "getSelectedItemButton";
|
||||
getSelectedItemButton.Size = new Size(130, 32);
|
||||
getSelectedItemButton.TabIndex = 4;
|
||||
getSelectedItemButton.Text = "Get selected item";
|
||||
getSelectedItemButton.UseVisualStyleBackColor = true;
|
||||
getSelectedItemButton.Click += getSelectedItemButton_Click;
|
||||
//
|
||||
// selectedItemLabel
|
||||
//
|
||||
selectedItemLabel.AutoSize = true;
|
||||
selectedItemLabel.Location = new Point(175, 108);
|
||||
selectedItemLabel.Name = "selectedItemLabel";
|
||||
selectedItemLabel.Size = new Size(84, 15);
|
||||
selectedItemLabel.TabIndex = 5;
|
||||
selectedItemLabel.Text = "Selected item: ";
|
||||
//
|
||||
// customTextBox
|
||||
//
|
||||
customTextBox.Location = new Point(370, 9);
|
||||
customTextBox.Margin = new Padding(3, 2, 3, 2);
|
||||
customTextBox.MaxLength = 5;
|
||||
customTextBox.MinLength = 0;
|
||||
customTextBox.Name = "customTextBox";
|
||||
customTextBox.Size = new Size(208, 23);
|
||||
customTextBox.TabIndex = 6;
|
||||
customTextBox.Value = "";
|
||||
//
|
||||
// errorCustomTextBoxLabel
|
||||
//
|
||||
errorCustomTextBoxLabel.AutoSize = true;
|
||||
errorCustomTextBoxLabel.Location = new Point(370, 68);
|
||||
errorCustomTextBoxLabel.Name = "errorCustomTextBoxLabel";
|
||||
errorCustomTextBoxLabel.Size = new Size(0, 15);
|
||||
errorCustomTextBoxLabel.TabIndex = 7;
|
||||
//
|
||||
// checkCustomTextBoxButton
|
||||
//
|
||||
checkCustomTextBoxButton.Location = new Point(370, 35);
|
||||
checkCustomTextBoxButton.Margin = new Padding(3, 2, 3, 2);
|
||||
checkCustomTextBoxButton.Name = "checkCustomTextBoxButton";
|
||||
checkCustomTextBoxButton.Size = new Size(208, 28);
|
||||
checkCustomTextBoxButton.TabIndex = 8;
|
||||
checkCustomTextBoxButton.Text = "Check";
|
||||
checkCustomTextBoxButton.UseVisualStyleBackColor = true;
|
||||
checkCustomTextBoxButton.Click += checkCustomTextBoxButton_Click;
|
||||
//
|
||||
// customDataTree
|
||||
//
|
||||
customDataTree.Location = new Point(25, 189);
|
||||
customDataTree.Name = "customDataTree";
|
||||
customDataTree.Size = new Size(281, 193);
|
||||
customDataTree.TabIndex = 9;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(342, 277);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(39, 15);
|
||||
label1.TabIndex = 10;
|
||||
label1.Text = "Name";
|
||||
//
|
||||
// nameTextBox
|
||||
//
|
||||
nameTextBox.Location = new Point(343, 295);
|
||||
nameTextBox.Name = "nameTextBox";
|
||||
nameTextBox.Size = new Size(152, 23);
|
||||
nameTextBox.TabIndex = 11;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(342, 233);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(50, 15);
|
||||
label2.TabIndex = 12;
|
||||
label2.Text = "Position";
|
||||
//
|
||||
// positionTextBox
|
||||
//
|
||||
positionTextBox.Location = new Point(343, 251);
|
||||
positionTextBox.Name = "positionTextBox";
|
||||
positionTextBox.Size = new Size(152, 23);
|
||||
positionTextBox.TabIndex = 13;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
label3.AutoSize = true;
|
||||
label3.Location = new Point(343, 189);
|
||||
label3.Name = "label3";
|
||||
label3.Size = new Size(76, 15);
|
||||
label3.TabIndex = 14;
|
||||
label3.Text = "Departament";
|
||||
//
|
||||
// addEmployeeButton
|
||||
//
|
||||
addEmployeeButton.Location = new Point(342, 324);
|
||||
addEmployeeButton.Name = "addEmployeeButton";
|
||||
addEmployeeButton.Size = new Size(152, 22);
|
||||
addEmployeeButton.TabIndex = 15;
|
||||
addEmployeeButton.Text = "Add employee";
|
||||
addEmployeeButton.UseVisualStyleBackColor = true;
|
||||
addEmployeeButton.Click += addEmployeeButton_Click;
|
||||
//
|
||||
// departamentComboBox
|
||||
//
|
||||
departamentComboBox.FormattingEnabled = true;
|
||||
departamentComboBox.Location = new Point(342, 207);
|
||||
departamentComboBox.Name = "departamentComboBox";
|
||||
departamentComboBox.Size = new Size(152, 23);
|
||||
departamentComboBox.TabIndex = 16;
|
||||
//
|
||||
// getSelectedTreeItemButton
|
||||
//
|
||||
getSelectedTreeItemButton.Location = new Point(342, 352);
|
||||
getSelectedTreeItemButton.Name = "getSelectedTreeItemButton";
|
||||
getSelectedTreeItemButton.Size = new Size(152, 30);
|
||||
getSelectedTreeItemButton.TabIndex = 17;
|
||||
getSelectedTreeItemButton.Text = "Get selected";
|
||||
getSelectedTreeItemButton.UseVisualStyleBackColor = true;
|
||||
getSelectedTreeItemButton.Click += getSelectedTreeItemButton_Click;
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(700, 407);
|
||||
Controls.Add(getSelectedTreeItemButton);
|
||||
Controls.Add(departamentComboBox);
|
||||
Controls.Add(addEmployeeButton);
|
||||
Controls.Add(label3);
|
||||
Controls.Add(positionTextBox);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(nameTextBox);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(customDataTree);
|
||||
Controls.Add(checkCustomTextBoxButton);
|
||||
Controls.Add(errorCustomTextBoxLabel);
|
||||
Controls.Add(customTextBox);
|
||||
Controls.Add(selectedItemLabel);
|
||||
Controls.Add(getSelectedItemButton);
|
||||
Controls.Add(listboxItemValuetextBox);
|
||||
Controls.Add(clearListboxButton);
|
||||
Controls.Add(addInListboxItemButton);
|
||||
Controls.Add(customCheckedListBox);
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "Form1";
|
||||
Text = "Form1";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private WinFormsLibrary1.CustomCheckedListBox customCheckedListBox;
|
||||
private Button addInListboxItemButton;
|
||||
private Button clearListboxButton;
|
||||
private TextBox listboxItemValuetextBox;
|
||||
private Button getSelectedItemButton;
|
||||
private Label selectedItemLabel;
|
||||
private WinFormsLibrary1.CustomTextBox customTextBox;
|
||||
private Label errorCustomTextBoxLabel;
|
||||
private Button checkCustomTextBoxButton;
|
||||
private WinFormsLibrary1.CustomDataTree customDataTree;
|
||||
private Label label1;
|
||||
private TextBox nameTextBox;
|
||||
private Label label2;
|
||||
private TextBox positionTextBox;
|
||||
private Label label3;
|
||||
private Button addEmployeeButton;
|
||||
private ComboBox departamentComboBox;
|
||||
private Button getSelectedTreeItemButton;
|
||||
}
|
||||
}
|
110
WinFormsApp1/Form1.cs
Normal file
110
WinFormsApp1/Form1.cs
Normal file
@ -0,0 +1,110 @@
|
||||
using System.Security.Cryptography.Xml;
|
||||
using WinFormsLibrary1;
|
||||
using WinFormsLibrary1.Errors;
|
||||
using WinFormsLibrary1.Models;
|
||||
|
||||
namespace WinFormsApp1
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
FillCustomCheckedListBox();
|
||||
FillCustomDataTree();
|
||||
}
|
||||
|
||||
private void FillCustomCheckedListBox()
|
||||
{
|
||||
List<string> list = new List<string>() { "Çíà÷åíèå 1", "Çíà÷åíèå 2", "Çíà÷åíèå 3" };
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
customCheckedListBox.AddItem(list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void FillCustomDataTree()
|
||||
{
|
||||
departamentComboBox.Items.Add("Îòäåë ïðîäàæ");
|
||||
departamentComboBox.Items.Add("Îòäåë àíàëèòèêè");
|
||||
departamentComboBox.Items.Add("IT îòäåë");
|
||||
|
||||
DataTreeNodeConfig config = new DataTreeNodeConfig(new List<string> { "Department", "Position", "Name" });
|
||||
customDataTree.LoadConfig(config);
|
||||
|
||||
List<Employee> employees = new List<Employee>
|
||||
{
|
||||
new Employee("Èâàíîâ Èâàí", "Ìåíåäæåð", "Îòäåë ïðîäàæ"),
|
||||
new Employee("Ïåòðîâ Ïåòð", "Àíàëèòèê", "Îòäåë àíàëèòèêè"),
|
||||
new Employee("Ñèäîðîâ Ñèäîð", "Ìåíåäæåð", "Îòäåë ïðîäàæ"),
|
||||
new Employee("Ìàðèÿ Ñìèðíîâà", "Ðàçðàáîò÷èê", "IT îòäåë"),
|
||||
new Employee("Îëüãà Ïåòðîâà", "Ìåíåäæåð", "Îòäåë ïðîäàæ"),
|
||||
};
|
||||
|
||||
foreach (var employee in employees)
|
||||
{
|
||||
customDataTree.AddObject(employee);
|
||||
}
|
||||
}
|
||||
|
||||
private void addInListboxItemButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
string value = listboxItemValuetextBox.Text;
|
||||
if (customCheckedListBox.Items.Contains(value)) customCheckedListBox.SelectedElement = value;
|
||||
else customCheckedListBox.AddItem(value);
|
||||
}
|
||||
|
||||
private void clearListboxButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
customCheckedListBox.Clear();
|
||||
}
|
||||
|
||||
private void getSelectedItemButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
string value = customCheckedListBox.SelectedElement;
|
||||
|
||||
if (value == string.Empty) selectedItemLabel.Text = "Selected item: ~empty value~";
|
||||
else selectedItemLabel.Text = "Selected item: " + value;
|
||||
}
|
||||
|
||||
private void checkCustomTextBoxButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
errorCustomTextBoxLabel.Text = customTextBox.Value == string.Empty ? "~empty value~" : customTextBox.Value;
|
||||
}
|
||||
catch (RangeNotSetException ex)
|
||||
{
|
||||
// Îáðàáàòûâàåì îøèáêó, åñëè äèàïàçîí íå çàäàí.
|
||||
MessageBox.Show(ex.Message, "Îøèáêà äèàïàçîíà", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
catch (TextLengthOutOfRangeException ex)
|
||||
{
|
||||
// Îáðàáàòûâàåì îøèáêó, åñëè äëèíà òåêñòà âíå äèàïàçîíà.
|
||||
MessageBox.Show(ex.Message, "Îøèáêà äëèíû òåêñòà", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
private void addEmployeeButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (positionTextBox.Text == null || nameTextBox.Text == null || departamentComboBox.SelectedItem == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
customDataTree.AddObject<Employee>(new(nameTextBox.Text, positionTextBox.Text, departamentComboBox.SelectedItem.ToString()));
|
||||
customDataTree.Update();
|
||||
}
|
||||
|
||||
private void getSelectedTreeItemButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Employee employee = customDataTree.GetSelectedObject<Employee>();
|
||||
if (employee == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
positionTextBox.Text = employee.Position;
|
||||
nameTextBox.Text = employee.Name;
|
||||
departamentComboBox.SelectedItem = employee.Department;
|
||||
}
|
||||
}
|
||||
}
|
120
WinFormsApp1/Form1.resx
Normal file
120
WinFormsApp1/Form1.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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
WinFormsApp1/Program.cs
Normal file
17
WinFormsApp1/Program.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace WinFormsApp1
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
15
WinFormsApp1/WinFormsApp1.csproj
Normal file
15
WinFormsApp1/WinFormsApp1.csproj
Normal file
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WinFormsLibrary1\WinFormsLibrary1.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
31
WinFormsLibrary1.sln
Normal file
31
WinFormsLibrary1.sln
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.8.34525.116
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsLibrary1", "WinFormsLibrary1\WinFormsLibrary1.csproj", "{349684DA-EAF6-4A22-AB7E-A98216AA5EA9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsApp1", "WinFormsApp1\WinFormsApp1.csproj", "{B0B10C32-032F-49CB-9ED6-70A0DEE05587}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{349684DA-EAF6-4A22-AB7E-A98216AA5EA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{349684DA-EAF6-4A22-AB7E-A98216AA5EA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{349684DA-EAF6-4A22-AB7E-A98216AA5EA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{349684DA-EAF6-4A22-AB7E-A98216AA5EA9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B0B10C32-032F-49CB-9ED6-70A0DEE05587}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B0B10C32-032F-49CB-9ED6-70A0DEE05587}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B0B10C32-032F-49CB-9ED6-70A0DEE05587}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B0B10C32-032F-49CB-9ED6-70A0DEE05587}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {BC3841E0-E2BA-4201-9D85-36D4B65C22E5}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
59
WinFormsLibrary1/CustomCheckedListBox.Designer.cs
generated
Normal file
59
WinFormsLibrary1/CustomCheckedListBox.Designer.cs
generated
Normal file
@ -0,0 +1,59 @@
|
||||
namespace WinFormsLibrary1
|
||||
{
|
||||
partial class CustomCheckedListBox
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
checkedListBox = new CheckedListBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// checkedListBox
|
||||
//
|
||||
checkedListBox.Dock = DockStyle.Fill;
|
||||
checkedListBox.FormattingEnabled = true;
|
||||
checkedListBox.Location = new Point(0, 0);
|
||||
checkedListBox.Name = "checkedListBox";
|
||||
checkedListBox.Size = new Size(281, 235);
|
||||
checkedListBox.TabIndex = 0;
|
||||
checkedListBox.ItemCheck += checkedListBox_ItemCheck;
|
||||
checkedListBox.SelectedIndexChanged += checkedListBox_SelectedIndexChanged;
|
||||
//
|
||||
// CustomCheckedListBox
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(checkedListBox);
|
||||
Name = "CustomCheckedListBox";
|
||||
Size = new Size(281, 235);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CheckedListBox checkedListBox;
|
||||
}
|
||||
}
|
80
WinFormsLibrary1/CustomCheckedListBox.cs
Normal file
80
WinFormsLibrary1/CustomCheckedListBox.cs
Normal file
@ -0,0 +1,80 @@
|
||||
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;
|
||||
|
||||
namespace WinFormsLibrary1
|
||||
{
|
||||
public partial class CustomCheckedListBox : UserControl
|
||||
{
|
||||
public CheckedListBox.ObjectCollection Items => checkedListBox.Items;
|
||||
private EventHandler _changeEvent;
|
||||
public CustomCheckedListBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
checkedListBox.Items.Clear();
|
||||
}
|
||||
|
||||
public string SelectedElement
|
||||
{
|
||||
get
|
||||
{
|
||||
if (checkedListBox.SelectedIndex > -1 && checkedListBox.GetItemChecked(checkedListBox.SelectedIndex))
|
||||
{
|
||||
return checkedListBox.SelectedItem.ToString();
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (checkedListBox.Items.Contains(value))
|
||||
{
|
||||
checkedListBox.SelectedItem = value;
|
||||
checkedListBox.SetItemChecked(checkedListBox.Items.IndexOf(value), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void checkedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
|
||||
{
|
||||
if (e.NewValue == CheckState.Checked && checkedListBox.CheckedItems.Count > 0)
|
||||
{
|
||||
checkedListBox.ItemCheck -= checkedListBox_ItemCheck;
|
||||
checkedListBox.SetItemChecked(checkedListBox.CheckedIndices[0], value: false);
|
||||
checkedListBox.ItemCheck += checkedListBox_ItemCheck;
|
||||
}
|
||||
}
|
||||
public void AddItem(string item)
|
||||
{
|
||||
if (item == string.Empty) return;
|
||||
checkedListBox.Items.Add(item);
|
||||
}
|
||||
private void checkedListBox_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
_changeEvent?.Invoke(sender, e);
|
||||
}
|
||||
|
||||
// Cобытие, вызываемое при смене значения
|
||||
public event EventHandler ChangeEvent
|
||||
{
|
||||
add
|
||||
{
|
||||
_changeEvent += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_changeEvent -= value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
120
WinFormsLibrary1/CustomCheckedListBox.resx
Normal file
120
WinFormsLibrary1/CustomCheckedListBox.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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
WinFormsLibrary1/CustomDataTree.Designer.cs
generated
Normal file
55
WinFormsLibrary1/CustomDataTree.Designer.cs
generated
Normal file
@ -0,0 +1,55 @@
|
||||
namespace WinFormsLibrary1
|
||||
{
|
||||
partial class CustomDataTree
|
||||
{
|
||||
/// <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.Dock = DockStyle.Fill;
|
||||
treeView.Location = new Point(0, 0);
|
||||
treeView.Name = "treeView";
|
||||
treeView.Size = new Size(150, 150);
|
||||
treeView.TabIndex = 0;
|
||||
//
|
||||
// CustomDataTree
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(treeView);
|
||||
Name = "CustomDataTree";
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private TreeView treeView;
|
||||
}
|
||||
}
|
114
WinFormsLibrary1/CustomDataTree.cs
Normal file
114
WinFormsLibrary1/CustomDataTree.cs
Normal file
@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace WinFormsLibrary1
|
||||
{
|
||||
public partial class CustomDataTree : UserControl
|
||||
{
|
||||
// Публичное свойство для установки и получения иерархии
|
||||
protected DataTreeNodeConfig Levels { get; set; }
|
||||
public CustomDataTree()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
treeView.Nodes.Clear();
|
||||
}
|
||||
|
||||
public void LoadConfig(DataTreeNodeConfig levels)
|
||||
{
|
||||
if (levels != null)
|
||||
{
|
||||
Levels = levels;
|
||||
}
|
||||
}
|
||||
|
||||
// Публичный метод для получения выбранной записи (для конечного элемента дерева)
|
||||
public T GetSelectedObject<T>() where T : class, new()
|
||||
{
|
||||
if (treeView.SelectedNode == null || Levels == null || treeView.SelectedNode.Nodes.Count > 0)
|
||||
{
|
||||
// сделать ошибки
|
||||
return null;
|
||||
}
|
||||
|
||||
T val = new T();
|
||||
|
||||
TreeNode currentNode = treeView.SelectedNode;
|
||||
int levelIndex = Levels.NodeNames.Count - 1;
|
||||
|
||||
while (currentNode != null && levelIndex >= 0)
|
||||
{
|
||||
// имя свойства
|
||||
string nodeName = Levels.NodeNames[levelIndex];
|
||||
string value = currentNode.Text;
|
||||
|
||||
// Получаем свойство по имени и устанавливаем его значение
|
||||
PropertyInfo property = val.GetType().GetProperty(nodeName);
|
||||
property?.SetValue(val, Convert.ChangeType(value, property.PropertyType));
|
||||
|
||||
// Переходим к родительскому узлу
|
||||
currentNode = currentNode.Parent;
|
||||
levelIndex--;
|
||||
}
|
||||
|
||||
// Если не прошли все уровни
|
||||
if (levelIndex >= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
// Метод для добавления объекта в TreeView
|
||||
public void AddObject<T>(T element)
|
||||
{
|
||||
if (Levels == null || element == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TreeNodeCollection currentNodeCollection = treeView.Nodes;
|
||||
|
||||
for (int i = 0; i < Levels.NodeNames.Count; i++)
|
||||
{
|
||||
string nodeName = Levels.NodeNames[i];
|
||||
PropertyInfo property = element.GetType().GetProperty(nodeName);
|
||||
if (property == null) continue;
|
||||
|
||||
string nodeValue = property.GetValue(element, null)?.ToString() ?? nodeName;
|
||||
|
||||
// Проверяем, существует ли уже ветка с таким именем
|
||||
TreeNode existingNode = null;
|
||||
foreach (TreeNode node in currentNodeCollection)
|
||||
{
|
||||
if (node.Text == nodeValue)
|
||||
{
|
||||
existingNode = node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Если ветка не существует
|
||||
if (existingNode == null)
|
||||
{
|
||||
existingNode = currentNodeCollection.Add(nodeValue);
|
||||
}
|
||||
|
||||
currentNodeCollection = existingNode.Nodes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
WinFormsLibrary1/CustomDataTree.resx
Normal file
120
WinFormsLibrary1/CustomDataTree.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
60
WinFormsLibrary1/CustomTextBox.Designer.cs
generated
Normal file
60
WinFormsLibrary1/CustomTextBox.Designer.cs
generated
Normal file
@ -0,0 +1,60 @@
|
||||
namespace WinFormsLibrary1
|
||||
{
|
||||
partial class CustomTextBox
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
textBox = new TextBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// textBox
|
||||
//
|
||||
textBox.Dock = DockStyle.Fill;
|
||||
textBox.Location = new Point(0, 0);
|
||||
textBox.Margin = new Padding(3, 2, 3, 2);
|
||||
textBox.Name = "textBox";
|
||||
textBox.Size = new Size(81, 23);
|
||||
textBox.TabIndex = 0;
|
||||
textBox.TextChanged += textBox1_TextChanged;
|
||||
//
|
||||
// CustomTextBox
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(textBox);
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "CustomTextBox";
|
||||
Size = new Size(81, 16);
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private TextBox textBox;
|
||||
}
|
||||
}
|
66
WinFormsLibrary1/CustomTextBox.cs
Normal file
66
WinFormsLibrary1/CustomTextBox.cs
Normal file
@ -0,0 +1,66 @@
|
||||
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 WinFormsLibrary1.Errors;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
|
||||
namespace WinFormsLibrary1
|
||||
{
|
||||
public partial class CustomTextBox : UserControl
|
||||
{
|
||||
public int? MinLength { get; set; } = null;
|
||||
public int? MaxLength { get; set; } = null;
|
||||
|
||||
public event EventHandler ValueChanged;
|
||||
|
||||
public string Value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (MinLength == null || MaxLength == null)
|
||||
throw new RangeNotSetException();
|
||||
|
||||
if (textBox.Text.Length < MinLength || textBox.Text.Length > MaxLength)
|
||||
throw new TextLengthOutOfRangeException(MinLength ?? -1, MaxLength ?? -1);
|
||||
|
||||
return textBox.Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (MinLength == null || MaxLength == null
|
||||
|| textBox.Text.Length < MinLength || textBox.Text.Length > MaxLength)
|
||||
return;
|
||||
|
||||
textBox.Text = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string CheckValue(string v)
|
||||
{
|
||||
if (MinLength == null || MaxLength == null)
|
||||
throw new RangeNotSetException();
|
||||
|
||||
if (v.Length < MinLength || v.Length > MaxLength)
|
||||
throw new TextLengthOutOfRangeException(MinLength ?? -1, MaxLength ?? -1);
|
||||
|
||||
return v;
|
||||
|
||||
}
|
||||
|
||||
public CustomTextBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void textBox1_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
ValueChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
120
WinFormsLibrary1/CustomTextBox.resx
Normal file
120
WinFormsLibrary1/CustomTextBox.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
18
WinFormsLibrary1/DataTreeNodeConfig.cs
Normal file
18
WinFormsLibrary1/DataTreeNodeConfig.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary1
|
||||
{
|
||||
public class DataTreeNodeConfig
|
||||
{
|
||||
public List<string> NodeNames { get; set; } = new List<string>();
|
||||
|
||||
public DataTreeNodeConfig(List<string> nodeNames, bool alwaysCreateNewBranch = false)
|
||||
{
|
||||
NodeNames = nodeNames;
|
||||
}
|
||||
}
|
||||
}
|
13
WinFormsLibrary1/Errors/RangeNotSetException.cs
Normal file
13
WinFormsLibrary1/Errors/RangeNotSetException.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary1.Errors
|
||||
{
|
||||
public class RangeNotSetException : Exception
|
||||
{
|
||||
public RangeNotSetException() : base("Диапазон длины текста не задан.") { }
|
||||
}
|
||||
}
|
20
WinFormsLibrary1/Errors/TextLengthOutOfRangeException.cs
Normal file
20
WinFormsLibrary1/Errors/TextLengthOutOfRangeException.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary1.Errors
|
||||
{
|
||||
public class TextLengthOutOfRangeException : Exception
|
||||
{
|
||||
public int MinLength { get; }
|
||||
public int MaxLength { get; }
|
||||
|
||||
public TextLengthOutOfRangeException(int minLength, int maxLength) : base($"Длина текста не входит в заданный диапазон [{minLength}, {maxLength}].")
|
||||
{
|
||||
MinLength = minLength;
|
||||
MaxLength = maxLength;
|
||||
}
|
||||
}
|
||||
}
|
22
WinFormsLibrary1/Models/Employee.cs
Normal file
22
WinFormsLibrary1/Models/Employee.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary1.Models
|
||||
{
|
||||
public class Employee
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Position { get; set; }
|
||||
public string Department { get; set; }
|
||||
public Employee() { }
|
||||
public Employee(string name, string position, string department)
|
||||
{
|
||||
Name = name;
|
||||
Position = position;
|
||||
Department = department;
|
||||
}
|
||||
}
|
||||
}
|
10
WinFormsLibrary1/WinFormsLibrary1.csproj
Normal file
10
WinFormsLibrary1/WinFormsLibrary1.csproj
Normal file
@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user